使用 arm-none-eabi-gcc、newlib 和 cmake 连接 C/C++ STM32 项目
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 正在添加 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
被忽略了。
相关文章:
- 为什么STM32不中断?
- 存根用于STM32单元测试的HAL库
- STM32使用HAL库的外部闪存读取设备ID
- 利用Mbed库建立STM32与PC机的串行USB通信
- 使用 arm-none-eabi-gcc、newlib 和 cmake 连接 C/C++ STM32 项目
- 为什么在STM32上未清除闪存页面
- STM32从PC上漂浮在USB上,Endianess挣扎
- C/C++ 从 STM32 中的另一个类获取大型数据,如 180 数组
- STM32 HAL 库警告,含 C++14 及以上
- STM32(使用Mbed在线)在较高模拟输入频率下显示延迟
- STM32 NVIC ADC中断未触发
- 发送数据LWIP STM32 PC
- 当我跳到应用程序时,中断无法工作(STM32)
- stm32的系统工作台中的stm32-fatfs库
- ARM STM32需要兼容的编译器
- 如何仅使用Linux终端刷新stm32
- C++ STM32用户定义的类构造函数问题
- 解释stm32上触摸屏控制器(ADS7843)的原始数据
- eclipse(stm32)Why中的项目资源管理器中,一些stderivi文件显示为灰色
- 针对 STM32 进行编译时"cast from 'uint8_t*' to 'uint16_t' loses precision"