This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc with math library


The correct compilation command for that code is:
gcc -o test test.c -lm

Quoting Jeffrey Holle <jeffholle@beu.midco.net>:

> 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
> >
> >
>
>
>




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]