The reason is that a c file is compiled today. After entering the following code
The gop12.c file code is roughly
# Include <stdio. h> <br/> # include <stdlib. h> <br/> # include <math. h> <br/> int main (INT argc, char * argv []) <br/>{< br/> // mathematical functions are used somewhere <br/>}
GCC compiles this file
Gcc-O gop12 gop12.c <br/>
Error
/Tmp/ccgjwwz6.o: In function 'main ':
Gop12.c :(. Text + 0x346): Undefined reference to 'ceil'
Gop12.c :(. Text + 0x3d4): Undefined reference to 'ceil'
Gop12.c :(. Text + 0x555): Undefined reference to 'ceil'
Gop12.c :(. Text + 0x617): Undefined reference to 'ceil'
Gop12.c :(. Text + 0x6d9): Undefined reference to 'ceil'
/Tmp/ccgjwwz6.o: gop12.c :(. Text + 0x991): More undefined references to 'ceil 'follow
Collect2: LD returned 1 exit status
I found the reason from this blog for a long time and expressed my heartfelt thanks to the blogger: http://chongchong.blog.edu.cn/2007/216174.html
I am using Ubuntu 10.0.4 + gcc4.43
In the new GCC version, GCC divides the standard library in c99 into libc and libm. libm includes some math libraries. h> (I used the ceil () function here), so if you want to use libm, you must add the compilation option-LM (that is, link libm). Otherwise, an error will be reported.
Correct the compilation command
Gcc-lm-O gop12 gop12.c
Compiled successfully.
Summary: when a special library is used, the corresponding link parameters should be added to the compilation command.