I'm having difficulty linking my STM32 project using CMake. The link command that is generated is:
/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
Unfortunately I get two sets of errors. The first is:
arm-none-eabi/bin/ld: warning: cannot find entry symbol arch_paths_first; defaulting to 0000000008000190
which indicates that there is no entry symbol, but in the LD file the first line of code is: ENTRY(Reset_Handler)
. The symbol Reset_Handler
is defined in a linked file startup_stm32l432xx.s
.
The second set of errors relate to the 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'
Which are supposed to be solved by linking -lnosys
, but the linker appears to be ignoring that.
Essentially, the linker appears to be ignoring some of the directives in the LD file and ignoring some of the flags I have passed. I realise it is probably something I am doing wrong, but I can't see what it is.
If I add -specs=nosys.specs
the latter two errors go away, but this shouldn't be necessary? Can someone please help me understand what is going wrong here?
Looks like CMake on OSX is adding the -Wl,-search_paths_first
which is unsupported for the gcc arm toolchain. Fix is to add this to the CMakelists.txt file:
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 ()
Fix is taken from here: https://github.com/kiibohd/controller/blob/master/Lib/CMake/build.cmake
Still have no idea about the -lnosys
being ignored though.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.