Sorry, you need to enable JavaScript to visit this website.

Problems with fpu commands like sqrt atan

Zedboard forums is currently read-only while it under goes maintenance.

3 posts / 0 new
Problems with fpu commands like sqrt atan

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?

RE: Problems with fpu commands like sqrt atan

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()
double angle = 60;
double square_number = 64;
double result = 0;

/* Calculate the tangent of an angle. */
result = tan(angle);

printf("The tangent of angle %f is %f\n", angle, result);

/* Calculate the square root of a square number. */
result = sqrt(square_number);

printf("The square root of %f is %f\n", 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




thank you