Compiling a base C file for an ARM processor

I am using the Yagarto recompilation of the GCC toolkit. I am trying to compile this simple program to get the executable .elf


int main(void)


I get arm-none-eabi-gcc main.c

an error message when I enter the command

c: / yagarto / bin /../ Library / GCC / arm-neither-EABI / 4.6.2 /../../../../ lever-nor-EABI / Lib \ libc.a (lib_a- exit.o): exit': C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.19.0/newlib/libc/stdlib/exit.c:65: undefined reference to

Returned 1 exit status in _exit 'collect2: ld function

What am I doing wrong?


source to share

2 answers

Newlib requires a symbol definition _exit

. There might also be other symbols you have to provide to make the newlib work:

Something like this should be sufficient (if you are compiling for a microcontroller, don't do this when you have an OS):

.globl _exit
    b     . // Loop until reset


Or in C:

void _exit(void) {
    while(1) {
        // Loop until reset


BTW: you can disable interrupts before spinning.

EDIT: Maybe more information. Yagarto includes Newlib as libc, which is a library that provides functions like printf()

, malloc()

etc. However, it cannot know how to send a character to the screen or console (in the case of printf), or how to exit if you call abort()

or exit()

. Therefore Newlib requires you to provide an implementation of a few basic functions, depending on which functionality you are using Newlib.



It depends on what platform you are running on, what platform you are compiling on, what toolchain you are using, etc. There is no easy answer.

However, CodeSourcery (now Mentor) makes a decent turnkey cross-compilation environment - it's just gcc and glibc compiled for your platform, but it's still a good place to start if you want to customize easily: / p>

Unfortunately, when Mentor bought CodeSourcery, they made the download procedure significantly more complicated than before, and now you need to register and receive a link sent to you by email, not just download something, but I have not yet found a less bad way to get gcc toolchain. (Suggestions needed ...)



All Articles