An explanation is given here:
So if your program is using math functions and including
math.h
, then you need to explicitly link the math library by passing the-lm
flag. The reason for this particular separation is that mathematicians are very picky about the way their math is being computed and they may want to use their own implementation of the math functions instead of the standard implementation. If the math functions were lumped intolibc.a
it wouldn't be possible to do that.
[Edit]
I'm not sure I agree with this, though. If you have a library which provides, say, sqrt()
, and you pass it before the standard library, a Unix linker will take your version, right?