我在使用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)。在链接文件startup_stm32l432xx.s中定义了符号Reset_Handler。
第二组错误与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,后两个错误就会消失,但这不应该是必要的吗?有没有人能帮我弄明白这里出了什么问题?
发布于 2017-08-25 12:19:21
看起来像是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被忽略一事,我仍然一无所知。
https://stackoverflow.com/questions/45874166
复制相似问题