输出:
gcc直接编译时会报错(sqrt函数未找到):
#gcc prime.c -o prime
/tmp/ccxA2pag.o: In function `prime':
prime.c:(.text+0x49): undefined reference to `sqrt'
prime.c:(.text+0x69): undefined reference to `sqrt'
collect2: ld returned 1 exit status
#man sqrt
......
#include
Link with -lm.
......
所以使用sqrt函数的文件中,要实现正常编译,需要在gcc编译时加上-lm即可。
[root@test7 c]# gcc -lm prime.c -o prime
[root@test7 c]# ./prime
Please input a number :
12
12 isn't a prime.
[root@test7 c]# ./prime
Please input a number :
13
13 is a prime.