cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor
6,137 Views
Registered: ‎06-09-2014

Standard C libraries - linker error

 

Hi,

 

I'm getting "undefined reference to 'sqrtf'" errors from the linker.  This is a standard C99 library function with declaration in math.h.  I've tried adding "-std=c99" arguments to the gcc compile and link settings.  Do I need to add the standard C libraries to the project?

 

What else could be the problem?

 

Cheers

 

0 Kudos
7 Replies
Highlighted
Xilinx Employee
Xilinx Employee
6,131 Views
Registered: ‎08-02-2007

Hi,


Can you post your c code that you would want to compile?

 

I see that this is already defined in math.h

 

extern float sqrtf _PARAMS((float));

 

Also please confirm which version of SDK you are using.

 

 

--Hem

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos
Highlighted
Contributor
Contributor
6,109 Views
Registered: ‎06-09-2014

Hem,

 

I'm using v2014.2.  The problem with posting the code is that I'm porting quite a large project with many source files.

 

Trying to produce some minimal code that shows the problem.  In the process so far I have found a couple of symptoms.

 

1. I get the same linker error when I change the function call to sqrt(), which is a C90 function.

 

2. I don't get the error if I remove it from the the file it is in, but call sqrtf() from main.c, the file that has main() in it.

 

3. Even with identical #include's I get the error for calls in 1 file, but not main.c.

 

4. It doesn't seem to be a name mangling problem, because I still get the error if I add the prototype "float sqrtf(float);" just before the function that calls it and gives the linker error.

 

5. The error is still there if I add libm.a to the project.

 

Still wracking my brain.

 

Steve

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
6,103 Views
Registered: ‎08-01-2008

You can try with clean projects in SDK. Sometimes cleaning the libraries may help. It may be old libraries weren't updated correctly.
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Highlighted
Contributor
Contributor
6,092 Views
Registered: ‎06-09-2014

OK I've managed to produce a minimal setup that gives me the error.

 

SDK created the hardware from the attached .hdf file.  I created a brand new baremetal hello_world application project, allowing SDK to create a new BSP.  I added "#include <math.h>" and a function that calls sqrt() to hello_world.c (to get the attached hello_world.c).  Saved hello_world.s and ....boom.... I got the "undefined refernce" linker error.

 

The fact that I'm the only person having this problem suggests I must be doing something blindingly obviously wrong, I have a corrupted installation, or there's some incompatibility between v2014.2 and WinXP.

 

0 Kudos
Highlighted
Contributor
Contributor
6,073 Views
Registered: ‎06-09-2014

I'm still interested in somebody trying this out to see if they get this error.  Anyone?

0 Kudos
Highlighted
Visitor
Visitor
5,340 Views
Registered: ‎11-22-2014

Try this, I got it from a Zedboard/Vivado workshop tutorial I have been using:

 

Right-click on the “Your Project” project in the Project Explorer, and choose “C/C++ Build Settings”.
 Choose the “ARM gcc linker  Libraries” section.
 Click the “Add...” button in the “Libraries” pane at the top. (The button is the one with the green “+” sign on the document icon)
 Type “m” in the entry field and then click “OK”.
 Click “OK” to return to the main SDK window.

Highlighted
Observer
Observer
3,691 Views
Registered: ‎02-20-2016

Thanks! your answer solved my problem!

0 Kudos