Thread: whats the -lm do ? info was just to overwhelming

  1. #1

    Unhappy whats the -lm do ? info was just to overwhelming

    Just would like to now what the gcc option -lm means/does

    I got into trouble using the sin function from math.h and found a message on the board from someone with the same problem.

    The answer suggested to use the -lm which also works for me.
    Ofcourse I would like to know now what it does. The info pages are just to overwhelming with info for a newbie like me.

  2. #2
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    the -lm option tells gcc to link (that's what the 'l' stands for) your code with the "math" (this what the math library is called) shared library. It's almost like DLL's in windows...
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  3. #3


    Ok, thanks but that gives me another question. I do not have to to use a parameter like -ls for linking the stdio so why do i have to do this for the math and not for stdio ?

    I thought they were both standard functions of ANSI-C ?

  4. #4
    Registered User alex's Avatar
    Join Date
    Sep 2001

    All non-mathematical ANSI-C functions are stored in libc.a/, which is always included automatically by gcc, the mathematical ANSI-C functions are stored in libm.a/, which is available if you install gcc, but is not automagically included like the MS and Borland compiler. Those compilers try to guess whether the math library is needed... The Borland compiler used to get it wrong sometimes, which they fixed in the newest version. The MS compiles used to get it right, but the latest MS compilers have this problem:

    #include <stdio.h>
    #include <math.h>
       printf("%e\n", 1.0);
    The MS compiler compiles this without a problem, but it gives runtime errors! (the math library is needed to convert the second argument into a string, but it is erroneously not linked to the binary)


  5. #5


    Thanks! Thats the stuff I want to know

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help displaying info from structure
    By kisiellll in forum C Programming
    Replies: 6
    Last Post: 04-04-2009, 12:51 PM
  2. Question about getting an info class from another Form
    By Joelito in forum C# Programming
    Replies: 0
    Last Post: 10-16-2006, 01:02 PM
  3. Help doing an e-mail program in c...
    By Tyler_Durden in forum C Programming
    Replies: 88
    Last Post: 01-02-2005, 03:12 PM
  4. Binary trees search problem...
    By Umoniel in forum C Programming
    Replies: 2
    Last Post: 02-22-2004, 02:29 PM
  5. Replies: 3
    Last Post: 12-06-2001, 05:30 AM