C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-28-2001, 12:07 PM   #1
oeleboele
Guest
 
Posts: n/a
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.
  Reply With Quote
Old 12-28-2001, 07:25 PM   #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!
Engineer is offline   Reply With Quote
Old 12-29-2001, 03:49 AM   #3
oeleboele
Guest
 
Posts: n/a
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 ?
  Reply With Quote
Old 12-29-2001, 06:21 AM   #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
alex is offline   Reply With Quote
Old 12-30-2001, 04:12 AM   #5
oeleboele
Guest
 
Posts: n/a
Wink

Thanks! Thats the stuff I want to know
  Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help displaying info from structure kisiellll C Programming 6 04-04-2009 12:51 PM
Question about getting an info class from another Form Joelito C# Programming 0 10-16-2006 01:02 PM
Help doing an e-mail program in c... Tyler_Durden C Programming 88 01-02-2005 03:12 PM
Binary trees search problem... Umoniel C Programming 2 02-22-2004 02:29 PM
Guys, I really, REALLY need your help getting info into a structure. (Please help!) Desperado C Programming 3 12-06-2001 05:30 AM


All times are GMT -6. The time now is 07:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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