non constant or forward reference address expression for section .ARM.extab 错误解决
编译时报错:
FAILED: STM32F103RET6_Test001.elf
cmd.exe /C "cd . && D:\ProgramFiles\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe -g -Wl,-gc-sections,--print-memory-usage,-Map=D:/ProjectCode/CLion/test/STM32F103RET6_Test001/cmake-build-debug-arm-stm32/STM32F103RET6_Test001.map -mcpu=cortex-m3 -mthumb -mthumb-interwork -T D:/ProjectCode/CLion/test/STM32F103RET6_Test001/STM32F103RETX_FLASH.ld CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Src/gpio.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Src/main.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Src/stm32f1xx_hal_msp.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Src/stm32f1xx_it.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Src/syscalls.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Src/sysmem.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Src/system_stm32f1xx.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Core/Startup/startup_stm32f103retx.s.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c.obj CMakeFiles/STM32F103RET6_Test001.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c.obj -o STM32F103RET6_Test001.elf && cmd.exe /C "cd /D D:\ProjectCode\CLion\test\STM32F103RET6_Test001\cmake-build-debug-arm-stm32 && arm-none-eabi-objcopy -Oihex D:/ProjectCode/CLion/test/STM32F103RET6_Test001/cmake-build-debug-arm-stm32/STM32F103RET6_Test001.elf D:/ProjectCode/CLion/test/STM32F103RET6_Test001/cmake-build-debug-arm-stm32/STM32F103RET6_Test001.hex && arm-none-eabi-objcopy -Obinary D:/ProjectCode/CLion/test/STM32F103RET6_Test001/cmake-build-debug-arm-stm32/STM32F103RET6_Test001.elf D:/ProjectCode/CLion/test/STM32F103RET6_Test001/cmake-build-debug-arm-stm32/STM32F103RET6_Test001.bin""
d:/programfiles/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe:D:/ProjectCode/CLion/test/STM32F103RET6_Test001/STM32F103RETX_FLASH.ld:88: non constant or forward reference address expression for section .ARM.extab
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
原因:
最新的 STM32CubeMx 生成的 .ld 文件中含有 READONLY 关键字,此关键字只能在 gcc 11 版本及以后使用,gcc 10及以下版本解析不了报错。(在后面生成的注释中也有说明)
解决方法:
打开 .ld 文件,删除所有 (READONLY) 字段
修改后: