Trying to compile an linux demo project with using sqrt and other math functions including of math.h results in compiler errors. is there no support or what option for compiler is needed?
Trying to compile an linux demo project with using sqrt and other math functions including of math.h results in compiler errors. is there no support or what option for compiler is needed?
Hi sbuechele,
I used 14.2 SDK to put together a quick application to test this out.
#include <math.h>
#include <stdio.h>
int main()
{
tdouble angle = 60;
tdouble square_number = 64;
tdouble result = 0;
t/* Calculate the tangent of an angle. */
tresult = tan(angle);
tprintf("The tangent of angle %f is %f
", angle, result);
t/* Calculate the square root of a square number. */
tresult = sqrt(square_number);
printf("The square root of %f is %f
", square_number, result);
return 0;
}
Sure enough, when I go to build I get the error message: "undefined reference to `sqrt'"
I did a 'man sqrt' and realized my error right away. The manual for these math functions show that this code must be linked against the math library by adding the '-lm' flag to your build command.
To do this in SDK, right click on your application project and select the C/C++ Build Settings option. Then click on the Tool Settings tab and locate the ARM Linux gcc linker-->Libraries pane and add the 'm' library.
Not only did the application build, but I was able to run it on ZedBoard also:
zynq> ./math_application.elf
The tangent of angle 60.000000 is 0.320040
The square root of 64.000000 is 8.000000
Regards,
-Kevin