What does -lm
option do in g++ and when is it needed?
Is there a complete description of g++ options?
The -g option instructs the compiler to generate debugging information during compilation. In C++, the -g option turns on debugging and turns off inlining of functions. The- g0 (zero) option turns on debugging and does not affect inlining of functions. You cannot debug inline functions with the -g0 option.
When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker.
The g++ Compiler Without this option, g++ creates an executable file. With this option, it creates an object file. If no output file name is given (by option -o), the object file name for file prog. cpp is prog.o. -g.
Options include control over which components get generated, assigning customized names to makefiles, and others.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With