-4

what does the option '-lm' mean when compiling a c program using gcc compiler. Please also mention other options that is included in gcc compiler.Thank you.

leppie
  • 115,091
  • 17
  • 196
  • 297
user299731
  • 25
  • 1
  • 7
  • 1
    Why did you tag this with `unity`? ... /o\ – leppie Aug 24 '14 at 16:30
  • 1
    It's the math library, I believe. – dfeuer Aug 24 '14 at 16:31
  • 1
    It just means link with the math library, `libm`. See the [gcc manual](https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/) for this and other command line options. – Paul R Aug 24 '14 at 16:31
  • 1
    Option `-l` followed by a name (`-lm` or `-l m`) is an instruction to the linker that means search for a library with a name `libm.a` or `libm.so` (or other variants on the extension). Note that GCC has multiple hundreds of options in total; no-one is going to relist a major section of the [GCC Manual](https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/) for you. – Jonathan Leffler Aug 24 '14 at 16:32
  • possible duplicate of [What does -lm option do in g++](http://stackoverflow.com/questions/10447791/what-does-lm-option-do-in-g) – Paul R Aug 24 '14 at 16:35
  • @PaulR: gritted teeth — no; it is a different compiler (G++ is not GCC). – Jonathan Leffler Aug 24 '14 at 16:36
  • @JonathanLeffler: hmm - debatable - but the linker flags are the same either way. – Paul R Aug 24 '14 at 16:38
  • @PaulR — 'debatable' hence the gritted teeth. But C and C++ are different languages. If the questions were tagged with the linker, or didn't specify the different languages, I'd go with 'exact duplicate'. But the exactness isn't great when it is two different compilers and languages, albeit the same linker in all probability. I get unhappy when C questions are duplicated to a C++ question and vice versa — but recognize others may have different opinions. – Jonathan Leffler Aug 24 '14 at 16:41
  • @JonathanLeffler: I agree when it's a language-specific question, but since this really only relates to linker flags (regardless of the C tag), I think it counts as a dupe. Also, note that the gcc/g++ C/C++ distinction is rather blurred, since gcc will happily compile C++ source files. – Paul R Aug 24 '14 at 16:45

1 Answers1

1

-lm links your program against math library, needed on some platforms when you use functions from <math.h>

Piotr Skotnicki
  • 46,953
  • 7
  • 118
  • 160
  • 2
    Needed on some platforms when you use ``; Mac OS X does not require it — the maths library functions are in the standard library, though there's a stub that means it does no harm to link with `-lm`. – Jonathan Leffler Aug 24 '14 at 16:34