This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Can't compile programs using functions in math.h
- From: bjorn rohde jensen <shamus at tdcadsl dot dk>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 03 Apr 2002 00:48:14 +0200
- Subject: Re: Can't compile programs using functions in math.h
- References: <F201Sox9fSRqymf0nV000005886@hotmail.com>
- Reply-to: shamus at tdcadsl dot dk
Hi Martin,
You need to link with the math library too, including the header is
not enough.
Try; gcc -o junk test.c -lm
Yours sincerely,
bjorn
Martin Rothberg wrote:
>
> I am running redhat 7.2. I can compile simple programs just fine, but I
> cannot compile programs the use functions such as sin or cos. I need these
> as I am doing navigation calculations. I have tried various things. I
> confirmed that the compiler is finding math.h and the underlying
> mathcalls.h. However, when I compile, I get:
>
> [root@mercury root]# gcc -o junk test.c
> /tmp/ccINr3XY.o: In function `main':
> /tmp/ccINr3XY.o(.text+0x41): undefined reference to `cos'
> collect2: ld returned 1 exit status
>
> I am not sure why it fails. I have attempted to build both on command line
> and via KDevelop (in case I forgot to set up something). Both yielded the
> same result. I even reinstalled the RPM's for gcc in case I had damaged the
> install, but the result was the same. Are there environment variables I
> need to explicitly set to use the standard C headers and libraries? Since
> the header files are intact, am I missing the library itself? Please advise
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx