我正在使用一个带双精度FPU的STM32 H753。
我首先尝试了以下编译和链接命令:
arm-none-eabi-gcc -mcpu=cortex-m7 -std=c99 -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -g3 -O1 -Wall -ffunction-sections -fdata-sections -fstack-usage xxx.c -o xxx.o
arm-none-eabi-gcc -T"xxx.ld" -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -nostdlib -Wl,-Map=xxx.map -o xxx.elf xxx.o -lm -lc
但有一个链接错误
xxx/arm-none-eabi/bin/ld: error: xxx.elf uses VFP register arguments, /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libm.a(lib_a-w_sqrt.o) does not
xxx/arm-none-eabi/bin/ld: failed to merge target specific data of file /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libm.a(lib_a-w_sqrt.o)
...
w_sqrt.c:(.text.sqrt+0x3c): undefined reference to `__aeabi_dcmpun'
xxx/arm-none-eabi/bin/ld: w_sqrt.c:(.text.sqrt+0x60): undefined reference to `__aeabi_dcmplt'
xxx/arm-none-eabi/bin/ld: w_sqrt.c:(.text.sqrt+0x98): undefined reference to `__aeabi_ddiv'
xxx/arm-none-eabi/bin/ld: /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libm.a(lib_a-e_sqrt.o): in function `__ieee754_sqrt':
...
collect2: error: ld returned 1 exit status
make: *** [makefile:76: base_gen_uP1.elf] Error 1
我假设使用了错误的数学库,所以我像这样指定了它的路径:
arm-none-eabi-gcc -T"xxx.ld" -L/opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/lib/thumb/v7e-m+dp/hard/ -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -nostdlib -Wl,-Map=xxx.map -o xxx.elf xxx.o -lm -lc
这工作(无链接错误,汇编代码正确,FPU指令被调用)。
然后我想尝试我的代码没有FPU指令和cuoldnot找到正确的编译/链接选项。我想下面的话是正确的
arm-none-eabi-gcc -mcpu=cortex-m7 -std=c99 -mfloat-abi=soft -mthumb
arm-none-eabi-gcc -T"xxx.ld" -mfloat-abi=soft -mthumb -nostdlib -Wl,-Map=xxx.map -o xxx.elf xxx.o -lm -lc
但我得到了(我也尝试了cortex-m7+nofp
,同样的事情)
xxx/arm-none-eabi/bin/ld: /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/nofp/libm.a(lib_a-w_sqrt.o): in function `sqrt':
w_sqrt.c:(.text.sqrt+0x22): undefined reference to `__aeabi_dcmpun'
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: w_sqrt.c:(.text.sqrt+0x32): undefined reference to `__aeabi_dcmplt'
...
1.为什么我必须手动添加启用FPU的数学库的路径?我猜GCC应该能够根据编译或链接选项找到正确的lib
1.我的FPU-disabled link命令有什么问题?
1条答案
按热度按时间brccelvz1#
对不起,我自己的答案,但我刚刚发现2),我忘记添加libgcc(选项-lgcc)。
由于我使用的是-nostdlib,我必须在link命令(选项-lc)中手动添加libm,但当不使用FPU时,libm还需要libgcc