roundf() function

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
guag_1662311
Level 1
Level 1
5 questions asked First reply posted First question asked

I am programming a CY8C5488AXI psoc. The program built successfully in the past. Now (after a few months), when I build it, I get the following error ( using PSoC Creator v4.4. with toolchain ARM GCC 5.4-2016-q2-update):

C:\ELENTECH Projects\Distiller Control\PSoC\Distiller_Control\Distiller_Control_Proto.cydsn/proj_support.c:2176: undefined reference to `roundf'
collect2.exe: error: ld returned 1 exit status
The command 'arm-none-eabi-gcc.exe' failed with exit code '1'.
--------------- Build Failed: 12/22/2021 10:17:52 ---------------

This error refers to the following statement  that calls roundf() (supposedly in math library):
temp =  roundf(DAC_ONEDEGREE_COUNT * ((float) degrees));


The program has the #include <math.h>  statement, which should declare the roundf() function.
Any suggestions/comments?
Thanks!

0 Likes
1 Solution
Krupashankar
Moderator
Moderator
Moderator
500 replies posted 50 likes received 25 likes received

Hi @guag_1662311,

Could you please try the below:

In Creator go to Project -> Build Settings -> Linker -> General

  Add "m" (without the quotes) into Additional Libraries. This will add the math library "Libm.a" to your project.

Krupashankar_0-1641316951653.png

 

Please let us know if this solves your problem.

 

Thanks,

Krupashankar

View solution in original post

0 Likes
4 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

guag,

Suggestion:  You can download earlier versions of Creator.

I've never used rountf() but I have used other functions in math lib with math.h.

It appears the math.h has no reference to the roundf() in the file.  This can be verified by looking at the math.h file.

I've added the roundf() function to a project.  Here's what I noticed:

I find the reference in math.h however it is ghosted

extern float roundf _PARAMS((float));

The ghosting is because the pre-compiler variable __ISO_C_VISIBLE  is not defined.  See the conditional compile below.

#if __ISO_C_VISIBLE >= 1999

I don't know the "official" way of turning this conditional compile variable on.  However I when I compiled, I got no complaints about the function being undefined.

I'm using Creator 4.3 with great success.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

In PSoC Creator, you can define preprocessor defines here:

Go to Project > Build Settings > ARM GCC Y.X > Compiler > General > Preprocessor Definitions. You can add:

__ISO_C_VISIBLE=XYZ

In your case, XYZ should be a number equal or higher than 1999.

0 Likes
guag_1662311
Level 1
Level 1
5 questions asked First reply posted First question asked

Hello,

I added the command to the preprocessor definitions as shown below. Still getting the undefined reference to `roundf' build error. Where is math.h in the toolchain directory? It was installed with the default settings.

Thank you.

guag_1662311_0-1640435782074.png

 

0 Likes
Krupashankar
Moderator
Moderator
Moderator
500 replies posted 50 likes received 25 likes received

Hi @guag_1662311,

Could you please try the below:

In Creator go to Project -> Build Settings -> Linker -> General

  Add "m" (without the quotes) into Additional Libraries. This will add the math library "Libm.a" to your project.

Krupashankar_0-1641316951653.png

 

Please let us know if this solves your problem.

 

Thanks,

Krupashankar

0 Likes