免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1432 | 回复: 1
打印 上一主题 下一主题

[函数] 求教:关于自定义库函数以及对访问库函数的方法的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-12-24 23:07 |只看该作者 |倒序浏览
我想自己定义一个库函数,自己简单的写了一个代码,编译一下,却出了点问题,代码如下:
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 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-12-24 23:11 |只看该作者
先把你的库文件编译成.o文件.
然后编译calendar.c 给 gcc 提供.o文件和你代着main的.c..就可以了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP