Zhanhailiang Date: 2014-10-25
Use GCC to compile such as the following code times "undefined reference to ' sin '":
#include <stdio.h>#include <math.h>#include <stdlib.h>Main() { DoubleA= Sin(1); Exit (0);}
[Root@~/Wade/Codereview/Learningc/9]# gcc-o Timetest timetest.c/Tmp/Ccizihf7.o:infunction `Func': timetest.c: (. text+0x3f): Undefined reference to ' sin 'Collect2:LDReturned1 ExitStatus
Usually due to the lack of a mathematical library, only need to manually add the GCC libm.so Library at compile time. For example, the following:
[Root@~/Wade/Codereview/Learningc/9]# gcc Timetest.c-lm-o timetest[Root@~/Wade/Codereview/Learningc/9]#./timetest
, by specifying the path of the corresponding library through-l, it defaults to the system library path, such as/lib and/USR/LIB64 (64-bit) ( this default system library path value to be confirmed by the author and then change ), Linux Library Unified naming specification is lib***.so, Therefore,-LM indicates that GCC defaults to the system library path and goes down to the libm.so library, such as the following:
[Root@/Usr/Lib64]# find/usr/lib64/|grep "libm.so"/Usr/Lib64/Libm.so[Root@/Usr/Lib64]# find/lib |grep "libm.so"
Undefined reference to ' sin& #39; problem solving