I am currently reading Advanced Linux Programming and in the section 2.3.3 it is said that if I use some function from math.h I have to link the object files with -lm. But I am pretty sure that I already used some math function like sqrt, pow or log without having to specify the use of this shared library.Do you see where the problem is?Thank you
Use math.h and link objects files without -lm
linux;gcc
You should always use -lm when using functions from math.h if you want to keep your code/makefiles portable.Some of the things in that header are macros (which obviously don't need additional libraries), but which are is not specified (except for a few ones). Some other functions might be implemented as build-ins by your compiler (even replaced by processor-specific opcodes directly), inlined, etc... so the correct linking of your code could also depend on optimizer settings and the exact compiler/version you're using.For example:#include <stdio.h>#include <math.h>int main(){    double d = 0.2;    fprintf(stdout, %f\n, sqrt(d));    return 0;}With GCC 4.5.1 on Linux:$ gcc -o t t.c/tmp/cczCfJsj.o: In function `main':t.c:(.text+0x30): undefined reference to `sqrt'collect2: ld returned 1 exit status$ gcc -O3 -o t t.c# ok, compiled and linked fineSo to save yourself a headache, just add -lm.