Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exit.c:(.text+0x18): undefined reference to `_exit' when using arm-none-eabi-gcc

Tags:

gcc

arm

I'm new to the field of microcontrollers. I need to port an IDE which is compiling programs for AVR microcontrollers to compile programs for ARM microcontrollers. I have just replaced the compiler from AVR to ARM and added some options as told by someone. The following is the command:

\ARM-GCC\bin\arm-none-eabi-gcc -O0 -ffunction-sections -Wall -std=gnu99 -mfloat-abi=soft  -Wa,-adhlns="[email protected]" -fmessage-length=0 -mcpu=cortex-m0 -mthumb -g3 -gdwarf-2 -Wl, --gc-sections -o <Dir_name>\Build_Files\Blink_arm.cpp.elf  <Dir_name>\Build_Files\Blink_arm.cpp.o <Dir_name>\Build_Files\core.a  -L<Dir_name>\Build_Files -lm  

When I execute it I get the follwing error:

tools/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.6.2\libc.a(lib_a-exit.o): In function `exit': exit.c:(.text+0x18): undefined reference to `_exit'   collect2: ld returned 1 exit status 

May I get some help on what is this error and how can I solve it. And also I don't know what those options in the command line specify.

like image 658
Sharath U Avatar asked Oct 17 '13 06:10

Sharath U


People also ask

How do you fix undefined references to Main?

When we compile these files separately, the first file gives “undefined reference” for the print function, while the second file gives “undefined reference” for the main function. The way to resolve this error is to compile both the files simultaneously (For example, by using g++).

What means none Eabi?

arm-none-eabi is the toolchain we use in this class. This toolchain targets the ARM architecture, has no vendor, does not target an operating system (i.e. targets a “bare metal” system), and complies with the ARM EABI.

What specs Nosys?

For example, nosys. specs just defines that system calls should be implemented as stubs that return errors when called ( -lnosys ). The choice of libc in this case depends on whether nano should be used. With %G the libgcc spec-string is processed, which defines the parameters passed to the linker.


1 Answers

This happens when compiling a file with arm-none-eabi-gcc in one machine/architecture to load it in an ARM target machine. Most probably you are not making use of semihosting, you want to retarget.

ARM® Compiler toolchain Version 4.1 indicates:

Semihosting is a mechanism that enables code running on an ARM target to communicate and use the Input/Output facilities on a host computer that is running a debugger.

From the toolchain's readme.txt (under folder .../gcc-arm-none-eabi-VERSION/share/doc/gcc-arm-none-eabi):

** non-semihosting/retarget

If you are using retarget, linking like: $ arm-none-eabi-gcc --specs=nosys.specs $(OTHER_LINK_OPTIONS)

For me --specs=nosys.specs was enough ;)

like image 119
Calamar Avatar answered Sep 18 '22 12:09

Calamar