LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 582|回复: 4

请教有关库函数引用的问题

[复制链接]
发表于 2003-9-27 23:12:32 | 显示全部楼层 |阅读模式
本人刚刚开始用linux里面的gcc编译c语言程序就遇到了不能引用库函数的问题:
测试程序如下:
#include<stdio.h>
#include<math.h>
main()
{ float a;
a=sin(10);
printf("the result is %.4f",a);
}
[hexing@localhost cprogram]$gcc -o test test.c
/tmp/ccIZ32b0.o:In function `main':
/tmp/ccIZ32b0.o(text+0xae):undefined reference to `sin'
collect2:ld returned 1 exit status
[hexing@localhost cprogram]$

能请教一下怎么解决吗?
先谢过了!!
发表于 2003-9-28 00:15:44 | 显示全部楼层
编译时加上 -lm
发表于 2003-9-28 08:16:56 | 显示全部楼层
出现这种问题时
man 那个ureference函数
里面会有详细说明
 楼主| 发表于 2003-9-28 09:50:26 | 显示全部楼层
谢谢二位了
这样就行了
但是不知道这个参数-lm是代表什么含义
难道gcc默认没有打开引用库函数的选项吗?
发表于 2003-9-28 14:08:08 | 显示全部楼层
-lm 是连接libm(就是math库),因为math库不常用,所以gcc默认不连接。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表