This article is from the Frequently Asked Questions for Linux, the Free/Open Source UNIX-like operating system kernel that runs on many modern computer systems. Maintained by David C. Merrill with numerous contributions by others. (v1.0).
A: Older run-time libraries included the math library in the C run-time library. It was not necessary to specify the math library separately when compiling. If the compiler generates a message like this when linking a program that uses math functions:
/tmp/ccDUQM4J.o: In function "main": /tmp/ccDUQM4J.o(.text+0x19): undefined reference to "sqrt" collect2: ld returned 1 exit status
You need use the -lm option with GCC to link with the math libraries:
# gcc -o program program.c -lm
Make sure also to use the statement #include <math.h> in the source file.
[Florian Schmidt]
 
Continue to: