[prog] Programming questions (Re: [Newchix] Another problem
learning C)
Almut Behrens
almut-behrens at gmx.net
Mon Apr 5 01:10:09 EST 2004
On Sun, Apr 04, 2004 at 09:58:07PM +0100, David Sumbler wrote:
> When I compile a program (taken from "Beginning Linux Programming") with
>
> gcc -o limits limits.c
>
> I get an error message. I have stripped out everything non-essential
> from the program for the purposes of this message, so the program now
> reads:
>
> #include <sys/types.h>
> #include <sys/resource.h>
> #include <sys/time.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <math.h>
>
> int main()
> {
> double x = 4.5;
> x = log(x*x + 3.21);
> }
>
> The error message I get (as with the full program) is:
>
> /tmp/ccaYPoJy.o(.text+0x39): In function `main':
> : undefined reference to `log'
> collect2: ld returned 1 exit status
You need to link with the math library. This is done with "-lm":
gcc -o limits limits.c -lm
The library contains the actual implementation of the log() function,
which is required, if you want to create an executable (in contrast to
simply compiling an object file with -c). math.h only contains the
prototypes (interface specifications).
Cheers,
Almut
More information about the Programming
mailing list