![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| some math problems in C | cdfd123 | High Level Programming | 4 | 08-19-2007 04:39 PM |
| Math calculation help | sickboy | Shell Programming and Scripting | 4 | 06-11-2005 10:22 AM |
| math.h not working? o.0 | primal | High Level Programming | 2 | 03-24-2002 06:23 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
### 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 ! |
|
#5
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|