gcc with math library

Jeffrey Holle jeffholle@beu.midco.net
Mon Jun 6 23:25:00 GMT 2005


Your error is from the linker.
I'd guess that you need to add "-lmath" to your gcc command line arguments.

Raphael Fonseca wrote:
> To GCC-GNU support team,
> 
> please help me with the following problem:
> 
> I installed gcc 3.4.1 in my linux PC directly through Mandrake version 
> 10.1.
> (I just klicked twice in the gcc package program and did not configure 
> by myself).
> 
> I can compile several programs, but I can not use math libraries.
> Even with simple programs like:
> 
>    /*     *  Simple test program -- simplified version of sample test 
> hello.
>     */
>    #include <stdlib.h>
>    #include <stdio.h>
>    #include <math.h>
> 
>    int main(void)
>    {
>    double f;
> 
>    f = sin(0.1) ;
>    printf( "Hello World \n" );
>    printf( " %f \n", f);
>    return 0;
>    }
> 
> When I try to compile with gcc -otest test.c         it  caused the 
> following error message:
> 
> /home/raphael/tmp/ccUXVGLx.o(.text+0x2c): In function `main':
> : undefined reference to `sin'
> collect2: ld returned 1 exit status
> 
> Without the "sin" function, the program is compiled and works.
> I imagine the compiler can not find the include files (<math.h>).
> I tried to put them in the test.c directory with no success in compilation.
> Is there any configuration problem? How to solve it?
> 
> Thank you,
> 
> Raphael
> 
> 



More information about the Gcc-help mailing list