Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By dimesp
#32297 I am new to C programming and I 've started a simple project in Eclipse.
I can't compile my project that uses a atan2 function.

my code looks like this (I 've added #include <math.h>) :
Code: Select all  double avgWindDir;
  double a=sumEastWest;
  double b=sumNorthSouth;
  avgWindDir = atan2(a, b);

The error is
/user_main.c:70: undefined reference to `atan2'

If for example I set :
Code: Select all  double a=1;
  double b=2;

it compiles ok.

I 've searched some other forums about this and they say it's a linker error and the solution is to add -lm to linker options.
Where is the correct place to add this option ?
User avatar
By jcmvbkbc
#32339
dimesp wrote:the solution is to add -lm to linker options.
Where is the correct place to add this option ?

Depends on the build system you use, in case of Makefiles add it to the LDFLAGS, LIBS or other similarly named variable that holds names of other libraries to link with.