[lug] OT: cc question

D. Stimits stimits at comcast.net
Wed Dec 3 15:23:31 MST 2003


Stephen Queen wrote:

>
>
> Ed Hill wrote:
>
> >
> >
> >
> > Yes, whenever using functions declared in "" you should also use
> > "-lm" at the end to link against the math library such as:
> >
> >  cc -o simple  simple.c -lm
> >
> > If you don't, then the linker ("ld") will complain about unresolved
> > symbols.
> >
> > Ed
> >
> >
> Is this a holder over from the days of math co-processors?

This is what allows linkable libraries, and is true even on other 
architectures that never used coprocessors. You always have to provide a 
compiled version of the functions you call, regardless of whether it is 
you who compiled it, or whether it is compiled in a system library. In 
the case of glibc, all of the programs link to this by default because 
of the way the compiler is set up, but in reality, everyone compiling C 
on linux is doing -lc even if they don't see it. The frontend of gcc 
does a lot more than people think about it doing in terms of setting up 
default library support. When you go to cross-compile you'll find out 
how much work is done by default. The math library libm just isn't there 
by default the way libc.so is. Inlining was mentioned, which means the 
called functions are compiled by the user once again, rather than by 
linking to an ouside source.

D. Stimits, stimits AT comcast DOT net




More information about the LUG mailing list