Results 1 to 9 of 9
Hi guys, I'm getting a compiler error "undefined reference to atan" and the same for sqrt when I pass in variables (doubles) . If I simply use a number e.g. ...
- 01-10-2012 #1Just Joined!
- Join Date
- May 2011
- Posts
- 6
atan and sqrt
Hi guys, I'm getting a compiler error "undefined reference to atan" and the same for sqrt when I pass in variables (doubles) . If I simply use a number e.g. atan(2) and sqrt(2) everything compiles fine.
I would really appreciate some help on this. I'm sure I'm doing something stupid, I just don't know what it is!
Thanks
- 01-11-2012 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Post your code here, please. And do use code blocks to enclose it so that indentations, and parens are not removed or mis-interpreted ( parens often end up as smileys ). It makes it a lot easier to read. Example:
Code:// This is some C++ code #include <iostream> int main (void) { // do something return 0; }Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 01-11-2012 #3Just Joined!
- Join Date
- May 2011
- Posts
- 6
atan and sqrt
Here is the code:
If i replace tmp3D and tmp2D with, say 2, in the sqrt and atan terms the program compiles fine otherwise I get the "undefined reference to sqrt" and "undefined reference to atan" messages. I also tried using atan2(northV, eastV) but got the same error message and could not get rid of it even substituting numbers.Code:void calcVelAndHdg(double northV, double eastV, double upV){ double vel2D, vel3D, hdg2D, tmp2D, tmp3D; tmp2D = pow(northV,2) + pow(eastV,2); tmp3D = pow(upV,2) + tmp2D; vel3D = sqrt(tmp3D) vel2D = sqrt(tmp2D); tmp2D = northV/eastV; hdg2D = atan(tmp2D); printf("2D velocity=%f 3D veloocity=%f 2D heading=%f \n\r", vel2D, vel3D, hdg2D); }
Thanks.
- 01-11-2012 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Did you #include <math.h>?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 01-11-2012 #5Just Joined!
- Join Date
- May 2011
- Posts
- 6
Yes i did. Also the text for the functions pow, atan and sqrt (and atan2 when I tried it) was highlighted in red on my dev window indicating they were recognized. Interestingly I had the same problem earlier problem with pow when I mistakenly used tmp2D=pow(northV,northV)+pow(eastV,eastV); but when I replaced with tmp2D=pow(northV,2)+pow(eastV,2); it compiled fine. FYI I am using DigiESP to develop an embedded application on a digi cc9p9215 (arm 9) module, with Ubuntu Linux on my dev computer.
Thanks.
- 01-11-2012 #6Just Joined!
- Join Date
- Aug 2011
- Posts
- 48
Did you use -lm when you compiled?
- 01-11-2012 #7Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Ok. Are you using the gcc compiler suite, or something else? Some embedded operating systems do not support floating point, so use integer versions of these functions, which only allows approximate solutions. Something to consider. The signature of atan() and pow() for Linux systems are:
You need to see what is in your math.h header.Code:double atan(double x); double pow(double x, double y);
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 01-11-2012 #8Just Joined!
- Join Date
- May 2011
- Posts
- 6
atan and sqrt
Sorry, was tied up on something else. No I did not use -lm when I compiled, I tried finding where to put it but couldn't. I'm using the digiESP development interface which is somewhat automated, so I just click on clean and build and the system does the rest. Also haven't yet been able to find the math.h library (obviously it's somewhere on the system but when I do an include the system just automatically finds it!)
As you can tell, I'm a bit of a novice at this!
I do know my system supports doubles and floats as I am already successfully using these elsewhere in the system.
Thanks
- 01-12-2012 #9Just Joined!
- Join Date
- May 2011
- Posts
- 6
Hi Rubberman, Just to let you know I finally managed to fix the problem. It was the -lm option in the compilation and after (a lot of) digging around I found where the command line was that I need to include the -lm in.
Thanks for all your help


Reply With Quote