62

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.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
matteoamc
  • 651
  • 1
  • 7
  • 5
  • 4
    Weird historical reasons, but mostly because It's How It Is: http://stackoverflow.com/questions/1033898/why-do-you-have-to-link-the-math-library-in-c – wkl Jan 05 '11 at 16:12

0 Answers0