math.h头文件问题
由于等级不够,不能发图片,抱歉请大家指出一下问题所在:
#include<stdio.h>
#include<math.h>
main()
{
int x=9;
printf("%d",sqrt(x));
return 0;
}
报的错是:
$ vim test_2.c
$ gcc test_2.c && ./a.out
/tmp/ccfVYFys.o: In function `main':
test_2.c:(.text+0x29): undefined reference to `sqrt'
collect2: ld returned 1 exit status
说明:跟小甲鱼安装的linux,但加了<math.h>却说 undefined reference to `sqrt' 为什么?
用下面的指令编译一下试试看:
gcc -lm -o test_2 test_2.c
如果通过编译,可执行程序的名字叫 test_2,用下面的指令运行:
./test_2 LINUX下面编译的时候还要手动链接 math库 gcc test_2.c -lm &&./a.out Krant5 发表于 2019-2-16 16:05
LINUX下面编译的时候还要手动链接 math库 gcc test_2.c -lm &&./a.out
试过了,可以解决了,谢谢! jackz007 发表于 2019-2-16 12:52
用下面的指令编译一下试试看:
谢谢!
页:
[1]