UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor
5,576 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
Xilinx Employee
Xilinx Employee
5,570 Views
Registered: ‎08-02-2007

Re: Standard C libraries - linker error

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
Contributor
Contributor
5,548 Views
Registered: ‎06-09-2014

Re: Standard C libraries - linker error

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
Xilinx Employee
Xilinx Employee
5,542 Views
Registered: ‎08-01-2008

Re: Standard C libraries - linker error

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
Contributor
Contributor
5,531 Views
Registered: ‎06-09-2014

Re: Standard C libraries - linker error

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
Contributor
Contributor
5,512 Views
Registered: ‎06-09-2014

Re: Standard C libraries - linker error

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

0 Kudos
Visitor studogger
Visitor
4,779 Views
Registered: ‎11-22-2014

Re: Standard C libraries - linker error

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.

Observer yingcai
Observer
3,130 Views
Registered: ‎02-20-2016

Re: Standard C libraries - linker error

Thanks! your answer solved my problem!

0 Kudos