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=arm-none-eabi-ld.exe
$(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
<snip>
/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
  • I've gotten the error about undefined "_exit";   I usually just create an _exit() function (which hopefully is never called, anyway.)

    I'm not sure why running ld instead of gcc as the linker would cause it to work - probably you're somehow getting a different libc/libgcc/whatever.  Is the path that it's picking up (/home/asic/lib/ARM/gcc-arm-none-eabi-10.3-2021.10/bin/) the same one where it is picking up arm-none-eabi-ld.exe ?  Does your makefile set an environment variables?  (what happens if you you put "LD=arm-none-eabi-gcc.exe" in the Makefile?  (wait!  Is this on two completely different computers??  (one windows and one linux?)

Reply
  • I've gotten the error about undefined "_exit";   I usually just create an _exit() function (which hopefully is never called, anyway.)

    I'm not sure why running ld instead of gcc as the linker would cause it to work - probably you're somehow getting a different libc/libgcc/whatever.  Is the path that it's picking up (/home/asic/lib/ARM/gcc-arm-none-eabi-10.3-2021.10/bin/) the same one where it is picking up arm-none-eabi-ld.exe ?  Does your makefile set an environment variables?  (what happens if you you put "LD=arm-none-eabi-gcc.exe" in the Makefile?  (wait!  Is this on two completely different computers??  (one windows and one linux?)

Children
No data