something about <math.h>

Hi, I got an easy problem for you but really difficult for me 'cause I am pretty new to this field
I got header file <math.h> included in my .c file , then I write the code as below:

   k = sqrt\(i\); /* both variables k and i are int */

then I cc temp.c
it says like this
undefined symbol first referenced in file
sqrt temp.o

it really makes me confused, so any one would like to give me a hand?
thanks a lot in avance!

Try:
cc -lm temp.c

The sqrt routine is in the math library. So you need to search the math library to build the executable program.

thanks for your suggestion,and I tried as you told me,but it remained the same error,,,
i386ld fatal: Symbol referencing errors. no output written to a.out

would you offer me more details ,thank you.

### first : the sqrt function requires a "double" parameter , and returns a double .

just like this :

/* ---- snip ---- */

double x = 2.0 ;
double y ;

y = sqrt (x) ;

/* ---- snip ---- */

### second : make sure the math library will be found :

$ find / -name libm.a

(it normally will be found in /lib or /usr/lib )

$ echo $LIBPATH or $LD_LIBRARY_PATH (depending on your o.s.) and
make sure the parent dir that contains libm.a is included in it .

### and finally , compile you program as follows :

$ cc -o yourprog yourprog.c -lm

(put the '-lm' at the end of the line)

good luck , and success !

thank you all.

it works by typing "cc temp.c -lm"

-lm should be added at the end of the line.

and I think the type sqrt(1) returns can be changed into int forcefully, so it isn't the right problem lying there.