math.h functions sqrt atan, and atan2

Please help. I am trying to use sqrt, and atan but can only successfully compile when I pass in actual numbers instead of variables (see code below). I am wondering if it is something to do with needing to use -lm when compiling (I have seen this on a number of posts) but I don’t know how or where to put it!

#include math.h

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 
           vel2D, vel3D, hdg2D);


If you are using Digi ESP, then go to project properties > C/C++ Make Project > Discovery Options > Compiler invocation command arguments.

Add -lm

and try…
Let me know if this is not working.