2017-08-25 1359 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想法是,雖然忽略。