undefined reference to `sqrt'

    技术2024-08-01  66

    root@ubuntu:/home/zhangbin/code# gcc area_point.c -o area_point

    /tmp/ccj0SoSt.o: In function `area_point':

    area_point.c:(.text+0x65): undefined reference to `sqrt'

    collect2: ld returned 1 exit status

    我有math.h,但是还是报错,找不到sqrt()函数. 搜索一下,原来是: http://www.linuxsir.org/bbs/showthread.php?t=343212 ===== 首先要对编译有个了解,你写了一个程序,如果有头文件的话,就需 要编译器指定这头文件对应的库文件, 库文件一般都在/usr/lib目录下。gcc默认指定的有几个库文件,比如libstd。 但是你所需要的 math库不是gcc默认指定的,所以就需要你在编译的时候加上一个-lm选项。 -l是指定XXX库,m就指math库。 ===== root@ubuntu:/home/zhangbin/code# gcc area_point.c -o area_point -lm 马上就好了!

    最新回复(0)