Solved: compilation error for ARM toolchain “undefined reference to `_exit'”

Our ARM toolchain was extracted at “/home/devlab/Desktop/helloworld/assembly/gcc-arm-none-eabi-10-2020-q4-major/” hence lets first try to add this toolchain to terminal path as,

export PATH=$PATH:/home/devlab/Desktop/helloworld/assembly/gcc-arm-none-eabi-10-2020-q4-major/bin

Now, we had written simple helloworld.c program, which we tried to compile as,

$ arm-none-eabi-gcc -o hello_world helloworld.c -g

But we got the compilation error as,

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-sbrkr.o): in function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk'

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-writer.o): in function `_write_r':
writer.c:(.text._write_r+0x24): undefined reference to `_write'

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-closer.o): in function `_close_r':
closer.c:(.text._close_r+0x18): undefined reference to `_close'

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-lseekr.o): in function `_lseek_r':
lseekr.c:(.text._lseek_r+0x24): undefined reference to `_lseek'

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-readr.o): in function `_read_r':
readr.c:(.text._read_r+0x24): undefined reference to `_read'

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-fstatr.o): in function `_fstat_r':
fstatr.c:(.text._fstat_r+0x1c): undefined reference to `_fstat'

TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: TOOLCHAIN/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/libg.a(lib_a-isattyr.o): in function `_isatty_r':
isattyr.c:(.text._isatty_r+0x18): undefined reference to `_isatty'
collect2: error: ld returned 1 exit status

Solution

This error can be solved by adding “–specs=nosys.specs” at the end of the command as,

$ arm-none-eabi-gcc -o hello_world helloworld.c -g --specs=nosys.specs

In above “nosys.specs” meaning these system calls would be ignored in normal functions but if we want to debug something in the code then we need to enable semihosting, where same above errors can be resolved by passing “–specs=rdimon.specs”


lynxbee_ezoic

Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )

   


Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded