Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `__aeabi_ddiv' and friends - building without stdlib but with -mfloat-abi=hard

Tags:

gcc

arm

cortex-m

I'm trying to build a project for Cortex-M4F. The Chip has a FPU, so I'm building with -mfpu=fpv4-sp-d16 -mfloat-abi=hard and I'm not using any libraries in order to save space, so I do -nostdlib -fno-builtin.

Now I want to use floating point operations, but when doing so I get a linker error:

led1642gw_gain.c:(.text.led_calculateGain+0xc): undefined reference to `__aeabi_f2d'
led1642gw_gain.c:(.text.led_calculateGain+0x24): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0x36): undefined reference to `__aeabi_dsub'
led1642gw_gain.c:(.text.led_calculateGain+0x48): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0x54): undefined reference to `__aeabi_d2f'
led1642gw_gain.c:(.text.led_calculateGain+0x9e): undefined reference to `__aeabi_f2d'
led1642gw_gain.c:(.text.led_calculateGain+0xb6): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0xc8): undefined reference to `__aeabi_dsub'
led1642gw_gain.c:(.text.led_calculateGain+0xda): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0xe6): undefined reference to `__aeabi_d2f'
led1642gw_gain.c:(.text.led_calculateGain+0x10c): undefined reference to `__aeabi_f2d'

Why is that? If I understand correctly, it shouldn't have to rely on library functions but use ARMs native FPU instructions for that.

like image 970
user1273684 Avatar asked Oct 21 '14 15:10

user1273684


2 Answers

Your core supports single-precision floating point instructions however your code works with double-precision floating point.

You can notice all the missing __aeabi stuff has a 'd' (as in double) mentioned.

If you have floating point literals in your code, by C standard they are considered double. You can force them into single-precision range by adding a f or F at the end of literal.

2.13.3 Floating literals: The type of a floating literal is double unless explicitly specified by a suffix. The suffixes f and F specify float...

like image 80
auselen Avatar answered Oct 11 '22 16:10

auselen


It is well known that in C, floating point literals (e.g. 1.23) have type double. As a consequence, any calculation that involves them is promoted to double.

To solve this, add 'f' to the end of all literals i.e.,

if (x < 2.5) ...

to

if (x < 2.5f) ...
like image 23
Fardin Abdi Avatar answered Oct 11 '22 18:10

Fardin Abdi