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

Re: sqrt C function



On Fri, 10 Aug 2001 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. i've tried using double as well as float variables. i'm 
> sure this is due to poor coding, but i'm looked at the man page and 
> linuxdoc.org and cannot find any example implementations of sqrt(). I'm 
> running i386 arch, and have math.h (as well as the complete gcc 3.0) 
> installed.


Does the error occur during the compile or link stage?

you need to link with the math library

the code above compiles fine for me using this command

 $ gcc -o test test.c -lm


cheers

dc


--------------------------------------------------------
But, with very few exceptions, it is the composers of
the tunes, not the writers of the words, which have
made our English hymns famous.  The average Englishman
will happily sing any words to a good tune.

                                        Reginald Frary
                               "Don't upset the choir"

David Purton

http://www.chariot.net.au/~dcpurton/
dcpurton@chariot.net.au



Reply to: