[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sqrt C function



R1nso13@aol.com wrote:

> when i try to use the sqrt function in gcc 3.0, and the gcc that's standard 
> with 2.2r3 ( i forget the version)  i get errors. here's some example code:
> 
> #include <math.h>
> #include <stdio.h>
> 
> double num;
> double num_root;
> 
> int main ()
> {
>     num = 4;
>     num_root = sqrt(num);
>     return (0);
> }
> 
> fails to compile.

If you're getting the error "undefined reference to sqrt", add -lm to
your gcc command line so that it will link to the math library.

In the future, when you want to ask about a problem like this, tell us
what error you're getting back. "I get errors" is totally uninformative,
and in many cases will make it impossible for anyone to figure out what
the problem might be. The biggest problem isn't simply that you got
errors, but that you didn't understand what the compiler told you about
the error. In which case, the right thing to do is tell us what the
compiler told you.

Craig



Reply to: