菜鸟问题,gcc编译过程中总是出错

软件和网站开发以及相关技术探讨
回复
lafeey
帖子: 21
注册时间: 2007-09-25 6:43

菜鸟问题,gcc编译过程中总是出错

#1

帖子 lafeey » 2007-10-05 12:00

近来在学习c语言,但编译过程中老是出错,不知道什么原因,请大侠们指导指导
源文件:

代码: 全选

#include<stdio.h>
#include<math.h>
int main()
{
double x,s;
printf("input number:\n");
scanf("%lf",&x);
s=sin(x);
printf("sine of %lf is %lf\n",x,s);
return 0;
}
每次编译都会出现:

代码: 全选

gcc test2.c -o test2
/tmp/cc5DZBgn.o: In function `main':
test2.c:(.text+0x37): undefined reference to `sin'
collect2: ld 返回 1
但是用下面的命令编译的话,程序能够正常运行

代码: 全选

 gcc test2.c -o test2 -lm
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

#2

帖子 dbzhang800 » 2007-10-05 13:44

你不是已经知道原因了吗?

用到了数学函数,链接的时候要 -lm
lafeey
帖子: 21
注册时间: 2007-09-25 6:43

#3

帖子 lafeey » 2007-10-05 13:50

:oops: 我是想知道有什么方法可以直接调库而不用另加参数。。。
回复