ripcobalt / terminal-ide

Automatically exported from code.google.com/p/terminal-ide
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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 commented 8 years ago
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