Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to some trigonometric functions in math.h C library #116

Open
GoogleCodeExporter opened this issue Mar 22, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link
Contributor

When trying to compile and link the following code using the terminal-gcc 
command for compiling C programs I get an undefined reference error.

#include <stdio.h>
#include <math.h>

int main()
{
  double a = 0.5;
  asin(a); // simple call to arc-sinus function in math.h
  return 0;
}

I get the following error: undefined reference to `asin'
I tried using int, float, long double, but nothing helps.
Oddly enough, when I use a constant value instead: "asin(0.5)" the code 
compiles with no errors.

I'm using terminal-ide system version v2.0 with GCC 4.4.0 (arm-eabi-gcc) on 
Adroid 4.0.4 running on a Prestigio tablet, model PMP5580c.

I've stumbled upon cases where the sin, cos, tan, functions would fail from the 
same linker error but this happens from time to time depending on the context 
they're used in.
I believe this is a general issue for all trigonometric functions in the math.h 
library and it's giving me a hard time running some C programs which use 
user-defined complex number calculations.

Original issue reported on code.google.com by zamfir.y...@gmail.com on 7 Sep 2014 at 11:44

@GoogleCodeExporter
Copy link
Contributor Author

Actually, I googled it a bit more and it turns out that I haven't passed the 
math C library to the linker when trying to compile. When I added -lm to the 
build command the error was resolved. Sorry for the false alarm, it's a GCC 
related thing but it really fooled me that when calling the function with a 
constant value the linker didn't complain at all.

Original comment by zamfir.y...@gmail.com on 7 Sep 2014 at 11:53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant