gcc: why is the -lm flag needed to link the math library?

matteoamc picture matteoamc · Jan 5, 2011 · Viewed 39.3k times · Source

If I include <stdlib.h> or <stdio.h> in a C program I don't have to link these when compiling but I do have to link to <math.h>, using -lm with gcc, for example:

gcc test.c -o test -lm

What is the reason for this? Why do I have to explicitly link the math library but not the other libraries?

Answer