link error: undefined reference to '_exit'

Asked by lobachevsky

hi, all,

I am trying to write a program for Cortex-M0 core.

The compile is success, but with link error by using the following flags in makefile

CFLAGS = --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group -mthumb -mcpu=cortex-m0

However, an error happens:

c:/program files/gnu tools arm embedded/4.7 2013q1/bin/../lib/gcc/arm-none-eabi/exit.c: (.text.exit+0x2c): undefined reference to '_exit'.

I have searched online, and read the readme under C:\Program Files\GNU Tools ARM Embedded\4.7 2013q1\share\doc\gcc-arm-none-eabi. They all said that a C lib is needed for the link, where --specs=rdimon.specs flag can solve the problem. However, without success.

Anyone knows how can I do?

Thanks a lot!

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
lobachevsky
Solved:
Last query:
Last reply:
Revision history for this message
chengbin (can-finner) said :
#1

Hi,
What's your linking command line? Could you dump the command line and paste it here?

And two points about linking static library for bare-metal programs:
1. Use arm-none-eabi-gcc, rather than arm-none-eabi-ld to do the job;
2. Always make sure that options like "-lc ..." are after *.c/*.o in command line.

Hoping this can help.

Revision history for this message
lobachevsky (nirvanno) said :
#2

hi, chengbin,

Thanks a lot for your answer.

I tried what you said like below:
$(CC) --specs=rdimon.specs -mthumb -mcpu=cortex-m0 $(OBJECTS) -Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group

where $(CC) is arm-none-eabi-gcc, and $(OBJECTS) is my object file, which are some *.o.

However, still with the error:
c:/program files/gnu tools arm embedded/4.7 2013q1/bin/../lib/gcc/arm-none-eabi/lib/libc.a(lib_a-exit.o): In function 'exit': exit.c": (.text.exit+0x2c): undefined reference to '_exit'.

Revision history for this message
Joey Ye (jinyun-ye) said :
#3

This is weird. It does work with my examples in hand. It might be a bug in tools or installation problem in a machine.

To verify, I'd suggest to reduce your project to just a hello-world progam with a simple object file, and see what happens.

It will be very helpful for us to address the issue if you can please try it and report the output.

Thanks,
Joey

Revision history for this message
lobachevsky (nirvanno) said :
#4

hi, Joey,

I have re-install my tool chain, and change the command as following:

arm-none-eabi-gcc main.c -mthumb -mcpu=cortex-m0 -Os --specs=nano.specs --specs=rdimon.specs -lc -lc -lrdimon -o main

And it was success.

So it seams something wrong with my installation & command sequence.

Any way, the problem is solved.

Thanks a lot for you advice.