- 论坛徽章:
- 0
|
我想自己定义一个库函数,自己简单的写了一个代码,编译一下,却出了点问题,代码如下:
cexicse.c 文件
#include <stdio.h>
int MonthDay(int year,int month)
{
int days=31;
if(month==4||month==6||month==9||month==11)
days=30;
if(month==2)
{
if((year%4==0&&year%100!=0)||year%400==0)
days=29;
else
days=28;
}
return days;
}
cexicise.h
#ifndef _cexcise_h
#define _cexcise_h
int MonthDay(int,int);
#endif
calendar.c调用以上头文件
#include "cexcise.h"
#include <stdio.h>
int main(void)
{
int monthday=MonthDay(2006,12);
printf("%d\n",monthday);
return 0;
}
编译 gcc -lm calendar.c 出现一个错误
[xihua@localhost excise]$ gcc -lm calendar.c
/tmp/ccBfzXNl.o: In function `main':
calendar.c.text+0x21): undefined reference to `MonthDay'
collect2: ld 返回 1
怎么解决,新手别见笑!
同时又问个问题,要对头文件的cexcise.c进行编译吗?
calendar.c是如何通过头文件cexcise.h来找到相关的.c文件的,它具体的链结过程是什么样的!
请各位大侠们指点指点小弟把!
[ 本帖最后由 melonmelon 于 2006-12-24 23:08 编辑 ] |
|