使用arm-none-eabi-gcc、newlib和cmake链接C/ c++ STM32项目

时间:2021-01-20 15:29:26

I'm having difficulty linking my STM32 project using CMake. The link command that is generated is:

使用CMake连接我的STM32项目有困难。生成的链接命令为:

/Users/jeremy/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-g++  -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fdata-sections -ffunction-sections -g -Og -gdwarf-2 -MMD -MP  -std=c++11 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -specs=nano.specs -T/Users/jeremy/stm32l432kc_freertos_template/STM32L432KCUx_FLASH.ld -Wl,-Map=target.map,--cref -Wl,--gc-sections 

< ... lots of .o files here ...>

-o stm32l432kc_freertos -lc -lm -lnosys

Unfortunately I get two sets of errors. The first is:

不幸的是,我有两组错误。第一个是:

arm-none-eabi/bin/ld: warning: cannot find entry symbol arch_paths_first; defaulting to 0000000008000190

which indicates that there is no entry symbol, but in the LD file the first line of code is: ENTRY(Reset_Handler). The symbol Reset_Handler is defined in a linked file startup_stm32l432xx.s.

这表明没有输入符号,但是在LD文件中,第一行代码是:entry (Reset_Handler)。符号Reset_Handler在一个链接文件startup_stm32l432xxs中定义。

The second set of errors relate to the stdlib:

第二组错误与stdlib有关:

/Users/jeremy/gcc-arm-none-eabi-6-2017-q2-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
/Users/jeremy/gcc-arm-none-eabi-6-2017-q2-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg_nano.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'

Which are supposed to be solved by linking -lnosys, but the linker appears to be ignoring that.

这应该通过链接-lnosys来解决,但是链接器似乎忽略了这一点。

Essentially, the linker appears to be ignoring some of the directives in the LD file and ignoring some of the flags I have passed. I realise it is probably something I am doing wrong, but I can't see what it is.

实际上,链接器似乎忽略了LD文件中的一些指令,而忽略了我传递的一些标志。我意识到这可能是我做错了什么,但我看不出它是什么。

If I add -specs=nosys.specs the latter two errors go away, but this shouldn't be necessary? Can someone please help me understand what is going wrong here?

如果我添加规格=好管闲事。说明后两个错误消失了,但这不应该是必须的吗?谁能帮我弄明白这里出了什么问题吗?

1 个解决方案

#1


0  

Looks like CMake on OSX is adding the -Wl,-search_paths_first which is unsupported for the gcc arm toolchain. Fix is to add this to the CMakelists.txt file:

看起来OSX上的CMake添加了-Wl,-search_paths_first,它不支持gcc arm工具链。修正是将这个添加到CMakelists。txt文件:

if ( APPLE )
    string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
    string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
endif ()

Fix is taken from here: https://github.com/kiibohd/controller/blob/master/Lib/CMake/build.cmake

修复从这里开始:https://github.com/kiibohd/controller/blob/master/Lib/CMake/build.cmake

Still have no idea about the -lnosys being ignored though.

不过,对lnosys的忽视仍然是不清楚的。

#1


0  

Looks like CMake on OSX is adding the -Wl,-search_paths_first which is unsupported for the gcc arm toolchain. Fix is to add this to the CMakelists.txt file:

看起来OSX上的CMake添加了-Wl,-search_paths_first,它不支持gcc arm工具链。修正是将这个添加到CMakelists。txt文件:

if ( APPLE )
    string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
    string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
endif ()

Fix is taken from here: https://github.com/kiibohd/controller/blob/master/Lib/CMake/build.cmake

修复从这里开始:https://github.com/kiibohd/controller/blob/master/Lib/CMake/build.cmake

Still have no idea about the -lnosys being ignored though.

不过,对lnosys的忽视仍然是不清楚的。