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.
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...
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) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With