gcc: why is the -lm flag needed to link the math library?

GccLibc

Gcc Problem Overview


I just discovered that the -lm flag is needed by gcc in order to compile a program that refers a function from the math library. I'm wondering why an explicit linking flag isn't needed when compiling programs containing other libraries such as the time library. If I write a program where the time() function is called, it would compile with no problems even with no linking options. But a program with the math library involved just won't work without the -lm flag.

Can anyone please explain the reason behind this behaviour? Thanks for your time.

Gcc Solutions


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmatteoamcView Question on Stackoverflow