PDA

View Full Version : Problem compiling C


fjleal
4th March 2004, 10:58 AM
Greetings!

I'm doing a simple C exercise on FC1 like this one:

#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[]) {
double a=log(100.0);
printf("%f\n", a);
exit(0);
}

when I invoke gcc ("gcc -o test test.c") I get the following error:

"
/tmp/cckCz1r1.o(.text+0x20): In function `main':
: undefined reference to `log'
collect2: ld returned 1 exit status
"

The "log()" function is defined in <math.h>. If I do a "gcc -o test test.c -E" (just to invoke the preprocessor, not the compiler nor the linker) I can see the code for the log() function (the preprocessor seems to do its job well).

So what may be the problem? Is it something related to FC1?

Thanks a lot. ;)

Bana
5th March 2004, 01:02 AM
This is weird, it does it on mine too and all math.h functions seem to be broken (at least I tested log() and sqrt()). I wonder what this is.

rocian
5th March 2004, 03:00 PM
You need to link to the math library in order
to use math functions:
gcc -o test -lm test.c
bye

fjleal
5th March 2004, 03:46 PM
Originally posted by rocian
You need to link to the math library in order
to use math functions:
gcc -o test -lm test.c
bye
Ok, it works! Thanks a lot rocian! ;)

phoxis
4th February 2008, 03:32 PM
how to do it with fedora eclipse?

Hegang - Colombo - Agadir -