[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cos() in math.h ?



On Thu, 3 Aug 2000, Christophe TROESTLER wrote:

> Thanks to all for answering my very simple question.  Now, how was I
> supposed to know I had to link against `m'?  I mean, given a header
> file, is the file I have to link against specified in the doc?  Is
> there any info on that subject you can refer me to?

Unfortunately there's no one-to-one correspondence between header files
and library files.  Although every library intended for development will
have a header (otherwise you could not compile programs designed to use
it), not every header has its own library - a given library can have
multiple header files, and some header files aren't associated with any
particular library.

Anyway, the short answer is that the definitions of functions don't
necessarily say what library you have to link to actually get them.  You
pretty much just have to know, pick it up from looking at other
examples... or go rooting around through the libraries looking for it...

You can get a list of functions in a library by using nm -C <file>.  Those
of class 'T' are function calls you can use.  (The -C makes it work with
C++ functions as well as C functions).
"nm -o -C *.a | grep <funcname>" is a good way of finding out which
library a given function is in, provided you know which directory the
library is in (/usr/lib is a good starting place :} ).  Don't forget that
when linking you don't specify the 'lib' or the '.a' - for example to link
with libm.a you just do -lm, not -llibm.a.

Symbols of class 'U' are not defined in this library, but rather are used
by this library but located somewhere else.  So don't be distracted by
those.

A library is really a collection of .o object files (see ar for more
details).  So nm (and other tools) will often tell you what object file
within the library is being referred to.  Normally, this only matters if
you are making your own libraries.



Reply to: