whats the -lm do ? info was just to overwhelming

This is a discussion on whats the -lm do ? info was just to overwhelming within the Linux Programming forums, part of the Platform Specific Boards category; Just would like to now what the gcc option -lm means/does I got into trouble using the sin function from ...

  1. #1
    oeleboele
    Guest

    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
    Posts
    125
    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
    oeleboele
    Guest

    Question

    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
    Posts
    132
    Hi!

    All non-mathematical ANSI-C functions are stored in libc.a/libc.so, which is always included automatically by gcc, the mathematical ANSI-C functions are stored in libm.a/libm.so, 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:

    Code:
    #include <stdio.h>
    #include <math.h>
    
    main()
    {
       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)

    alex

  5. #5
    oeleboele
    Guest

    Wink

    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, 02:12 PM
  4. Binary trees search problem...
    By Umoniel in forum C Programming
    Replies: 2
    Last Post: 02-22-2004, 01:29 PM
  5. Replies: 3
    Last Post: 12-06-2001, 04:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21