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

Re: Linking c programs?



Hi,

When you compile a library function into your program the system has to be told in which libraries to look for these references during linking.  A small set of libraries such as stdio are always checked for by the compiler - but it doesn't check all the libraries for references to functions as this would take *way* too long.

If your library is in the standard place of /lib/ then you only have to specify it's short name, if it is in a non-standard place you have to specify the full path eg /home/steve/lib.  The standard places to look are defined for the system with ldconfig.

So you should be able to compile with:

gcc -Wall -o it it.c -lm

The -l is for link and the m is the shortest name for the library which is unique e.g lib<name>.<major>.<minor>.  There is some explanation of why the library has to come last but I can't remember! 

If your gonna spend any time programming yourself I'd recommend the Prgogramming with Free Software from O'Reilly or Beginning Linux Programming from Wrox.  Generally I haven't been able to find comparable 'easy to read' web content :(

HTH

Steve

On Sun, Jul 04, 1999 at 05:10:59PM +0100, Andrew Holmes wrote:
> Hi,
> 
> I've been trying to compile a c program which uses maths functions like pow()
> and cbrt(), I've included the #include <math.h> and it compiles to an object
> ok. However when I try to compile it to a program I get:
> 
> /tmp/ccc13322: In function `difi':
> /tmp/ccc13322(.text+0xea): undefined reference to `cbrt'
> 
> Am I supposed to use some command line to gcc to make it work, I've been using 
> 
> gcc -o it it.c
> 
> to make a program called 'it' from the source 'it.c'
> 
> Any help would be greatly appreciated, TIA
> -- 
> Best Wishes,
> Andy Holmes <andy@proxima.force9.co.uk>
> 
> We are MicroSoft.  You will be assimilated.  Resistance is futile.
>         -- Attributed to B.G., Gill Bates
> 
> 
> -- 
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null
> 


Reply to: