Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does -lm option do in g++?

Tags:

What does -lm option do in g++ and when is it needed?

Is there a complete description of g++ options?

like image 545
a-z Avatar asked May 04 '12 11:05

a-z


People also ask

What does the '- G option do?

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.

What does option mean in GCC?

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.

What is option G ++?

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.

What is option in Makefile?

Options include control over which components get generated, assigning customized names to makefiles, and others.


2 Answers

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>.

like image 135
Mat Avatar answered Oct 17 '22 02:10

Mat


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...

like image 26
Evgeni Sergeev Avatar answered Oct 17 '22 03:10

Evgeni Sergeev