[prog] using a -ln option with GCC when compiling c code with math.h

Guru - haunter03 at hotmail.com
Mon Jun 23 22:09:41 EST 2003


"They are *not* part of the C language per se - they are functions written 
*in* C, so you don't have to implement them each time you write an 
application. These functions live in the "standard C library" - also known 
as libc. This is why things can go horribly horribly wrong when you upgrade 
libc - if you get yourself wedged in a situation where libc doesn't work, 
you can be pretty stuffed, because even the basic programs such as "cp", 
"mv" and the more complicated ones like "rpm" or "dpkg" are usually 
dynamically linked - that is to say, they rely on being able to load libc at 
run-time to use those
vital functions."
thanks for the information.

>In any case, at some point a Decision Was Taken, that mathematical 
>functions
>such as cos, sin - in fact, anything that uses math.h - are not vital 
>enough
>to live in the standard C library. Instead, they have their own library,
>usually in /usr/lib/libm.a, where they are stored.
>
>A library (well, the .a variety anyway) is in fact just an archive file
>(created using the "ar" archiver), containing a lot of .o files. When you
>pass gcc something like:
>
>gcc -o myprog proggie.c -lm
>
>...gcc will look in all the library directories (/lib, /usr/lib,
>/usr/local/lib, etc) for a file called "libm.a", and link all the .o files 
>in
>that archive as well to create the final executable.
>
>Borland just hides this entire process from you, which is why you haven't
>encountered it yet. By the way, why did you say "-ln" there - surely you 
>mean
>"-lm"? On my system, there is no such file as "libn.a", which is what gcc
>would look for if you were to specify that option on the command line.
>
>Meredydd
I probably made a spelling mistake, couldnt remember if it was -lm or -ln, 
it must be -lm. Sorry.
But what exactly does math.h contain then?
And what exactly is a .o file?
How do you know if something lives in a library instead of the standard C 
distribution?

Thanks for the help so far.

_________________________________________________________________
Hotmail is now available on Australian mobile phones. Go to  
http://ninemsn.com.au/mobilecentral/signup.asp



More information about the Programming mailing list