[英]Linking C/C++ STM32 project using arm-none-eabi-gcc, newlib and cmake
我在使用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
不幸的是,我遇到兩套錯誤。 第一個是:
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
,則后兩個錯誤將消失,但這不是必須的嗎? 有人可以幫我了解這里出了什么問題嗎?
看起來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 ()
修復程序從這里獲取: https : //github.com/kiibohd/controller/blob/master/Lib/CMake/build.cmake
仍然不知道-lnosys
被忽略的想法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.