tags:

views:

73

answers:

2

I had to compile a small little C program using the following;

gcc sine.c -o sine -lm

I needed the "-lm" because the program included the math.h.

In looking this up under compiler commands man shows it a either -llibrary or -l library.

I could not find any information on what other libraries. Apparently -lm is needed for math.h what other library commands might be needed.

Thanks

+5  A: 

-lm means to link the "m" library, which as you said contains math stuff. If you need other libraries for your code, your documentation for those functions will show that.

Blindy
Technically it means to *link* the "m" library, not load
Tyler McHenry
Well load first, then link it :)
Blindy
A: 

If it links without errors, you don't need anything anything else. In fact you don't even need to specify -lm, as it and the standard C library are linked automatically.

Paul Richter
I think `-lm` was just an example here ...
Tim Post
gcc takes the idiosyncratic approach to the maths library - it leads to lots and lots of fun when students do their first gcc practical.
Martin Beckett
The math library is _not_ linked automatically. Exactly which operations are in libm, however, depend on the OS and CPU architecture.
bdonlan
Indeed - and sometimes you need to add `-lmx` as well to get some of the less frequently used math functions, e.g. `log2f`.
Paul R