Linking with arm-none-eabi-gcc instead of arm-none-eabi-ld

I am working with a small sample project that targets Cortex-M4 using the gcc arm-none-eabi toolchain.  The makefile invokes arm-none-eabi-ld directly to link the executable:

$(LD) main.o retarget.o exceptions.o test_main.o common.o init_main.o -T link.ld --print-memory-usage -o $(TARGET)
I want to replace the makefile with one generated by CMake.  CMake always uses arm-none-eabi-gcc for the linker stage. My understanding is that arm-none-eabi-gcc calls arm-none-eabi-ld implicitly to do the actual linking.
My problem is that the CMake script isn't working so I tried running the linker steps manually.
If I use arm-none-eabi-ld explicitly, the linking works.  But if I use arm-none-eabi-gcc the linking fails:

$ arm-none-eabi-gcc -v CMakeFiles/wdt_interrupt_gnu.dir/main.c.obj CMakeFiles/wdt_interrupt_gnu.dir/retarget.c.obj CMakeFiles/wdt_interrupt_gnu.dir/exceptions.c.obj CMakeFiles/wdt_interrupt_gnu.dir/test_main.c.obj CMakeFiles/wdt_interrupt_gnu.dir/common.c.obj CMakeFiles/wdt_interrupt_gnu.dir/init_main.c.obj -T ../link_cmake.ld -o cm4.axf
/home/asic/lib/ARM/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /home/asic/lib/ARM/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2: error: ld returned 1 exit status

Do I need to pass arm-none-eabi-ld explicitly as a parameter to arm-none-eabi-gcc?

Parents Reply Children
No data