对‘sqrt’未定义的引用 collect2: error: ld returned 1 exit status

今天在调用数学库函数的时候,在Linux中使用的编译器中出现:

/tmp/ccmfxE8L.o:在函数‘main’中:
testcgen.c:(.text+0x23):对‘sqrt’未定义的引用
collect2: error: ld returned 1 exit status
对‘sqrt’未定义的引用 collect2: error: ld returned 1 exit status_第1张图片
说是因为不能链接到数学库函数

这时我们只需要在编译的指令 加上 -lm就可以了


gcc test.c -o  test  -lm

如图所示:

完美的解决了这个问题!!

你可能感兴趣的:(Linux函数)