2017-08-25 133 views
0

使用CMake链接我的STM32项目时遇到了困难。生成的链接命令是:使用arm-none-eabi-gcc,newlib和cmake链接C/C++ 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 

不幸的是,我得到了两组错误。第一个是:

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

这表明不存在条目的象征,但在LD文件的第一行代码是:ENTRY(Reset_Handler)。符号Reset_Handler在链接文件startup_stm32l432xx.s中定义。

第二组的错误涉及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' 

,这是为了通过连接-lnosys来解决,但链接似乎忽略了。

本质上,链接器似乎忽略了LD文件中的一些指令,并忽略了一些已通过的标志。我意识到这可能是我做错了,但我看不到它是什么。

如果我加-specs=nosys.specs后两个错误消失了,但这不应该是必要的吗?有人能帮我理解这里出了什么问题吗?

回答

0

看起来像OSX上的CMake添加了gcc arm工具链不支持的-Wl,-search_paths_first。解决方法是将其添加到的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() 

修复就是从这里取:https://github.com/kiibohd/controller/blob/master/Lib/CMake/build.cmake

仍然没有关于-lnosys想法是,虽然忽略。