Hi

Itamar S.-T. wrote:
> 
> Compiling the following example program:
>       #include <math.h>
> 
>       int main(void) {
>               double x = sqrt(2.0);
>               return 1;
>       }
> 
> Gives me the following error:
>       [itamar@porthos hashtest]$ gcc math.c 
>       /tmp/cc1Mfpzc.o: In function `main':
>       /tmp/cc1Mfpzc.o(.text+0xe): undefined reference to `sqrt'
>       collect2: ld returned 1 exit status

You need to link it with libm, e.g.
gcc file.c -lm
(or better gcc -c file.c; gcc file.o -lm)

> 
> What is the problem here?  I'm getting such an error any time I try to use
> functions from math.h.  This is RH6 (glibc 2.1, egcs 1.1.2).

This is really an FAQ, look for any C book (or GCC FAQ, or whatever).

> 
> -- 
> Itamar - [EMAIL PROTECTED]
> 
> =================================================================
> To unsubscribe, send mail to [EMAIL PROTECTED] with
> the word "unsubscribe" in the message body, e.g., run the command
> echo unsubscribe | mail [EMAIL PROTECTED]
> 

        didi

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to