What does -lm option do in g++?

2019-02-06 02:12发布

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

Is there a complete description of g++ options?

标签: gcc g++
2条回答
劳资没心,怎么记你
2楼-- · 2019-02-06 02:55

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

查看更多
smile是对你的礼貌
3楼-- · 2019-02-06 02:58

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

查看更多
登录 后发表回答