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

C++ 链接C/C++;使用arm none eabi gcc、newlib和cmake的STM32项目,c++,gcc,cmake,stm32,C++,Gcc,Cmake,Stm32,我很难使用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_p

我很难使用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
这表示没有条目符号,但在LD文件中,第一行代码是:
entry(Reset\u Handler)
。符号
Reset\u Handler
在链接文件
startup\u stm32l432x.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正在首先添加gcc arm工具链不支持的
-Wl,-search\u paths\u
。修复方法是将其添加到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 ()
修正从这里开始:


仍然不知道是否忽略了
-lnosys

看起来OSX上的CMake正在首先添加gcc arm工具链不支持的
-Wl,-search\u paths\u
。修复方法是将其添加到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 ()
修正从这里开始:

但是仍然不知道是否忽略了
-lnosys