- gcc sqrt function

Ted ted@hardwicke.co.uk
Thu Oct 21 07:45:00 GMT 1999

Dear Sirs,
I am sorry to trouble you with this query, since my problems may be due
to ignorance on my part.

I am starting to learn how to program in C, and I am having problems
using the `sqrt' function.
I am using a PII PC running Redhat 6.0 Linux.
The version of gcc is:-  egcs-2.91.66  19990314/Linux
The math.h header file is present in the `/usr/include' directory.
The following file is taken from `Teach Yourself C' by Schildt, page

#include <stdio.h>
#include <math.h>

int main(void)
    double answer;

    answer = sqrt(10.0);
    printf("%f", answer);

    return 0;

When I try to compile this with the command:-

`gcc -g -Wall -osqrt sqrt.c'

I get the error message:-

`8: undefined reference to `sqrt.'
`collect2: ld returned 1 exit status'

Is there a bug in gcc, or am I not using the function correctly?  I have
searched through the gcc info file, but I can't seem to find a solution.

Many thanks in anticipation.
Ted Mason

More information about the Gcc-bugs mailing list