What does -lm
option do in g++ and when is it needed?
Is there a complete description of g++ options?
What does -lm
option do in g++ and when is it needed?
Is there a complete description of g++ options?
That's a linker option. It tells the linker to link with (-l
) the m
library (libm.so/dll). That's the math library. You often need it if you #include <math.h>
.
The option does nothing for g++
: referring to this answer https://stackoverflow.com/a/1033940/1143274 libstdc++
requires libm
, so it will always be linked by g++
.
However, there is also some sort of an automatic linking behaviour for gcc
, investigated on this thread http://www.linuxforums.org/forum/programming-scripting/125526-c-gcc-math-h-lm.html which I can't seem to find an answer as to where that comes from and which libraries it applies to...