EmbDev.net

Forum: ARM programming with GCC/GNU tools arm-elf-ld problem, undefined reference to `__gccmain'


von (unknown) (Guest)


Attached files:

Rate this post
0 useful
not useful
Hello, I have problems when I am trying to link together a project 
example which I found on the net (I have attached the important files, 
just type make main.elf in the terminal).

When the following command is executed:
arm-elf-ld -v -lc -Map main.map -nostartfiles -T ld_flash.cmd -o 
main.elf crt.o main.o

I get this error message:
main.o(.text+0x1e4): In function `main':
home.../main.c:153: undefined reference to `__gccmain'

I suppose it is some library problem and I have tried a lot of different 
ways of including libc.a, but still I have not got it to work?

/Dan

von skriptkiddy (Guest)


Rate this post
0 useful
not useful
I successfully build the project using Codesourcery ARM 2011.03.

von Rolf Magnus (Guest)


Rate this post
0 useful
not useful
__gccmain is in libgcc, not in libc.

von (unknown) (Guest)


Rate this post
0 useful
not useful
Thank you for the replies.

@ Rolf Magnus, I have tired libgcc as well. When I run the command using 
libgcc:

arm-elf-ld -v -g -O0 -T ld_flash.cmd -o main.elf crt.o main.o 
-L/usr/local/lib/gcc-lib/arm-elf/2.95.3 -L/usr/local/arm-elf/lib/ -lgcc

I get the following error message:
/usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.text+0xbc): In 
function `__do_global_ctors':
: undefined reference to `atexit'
/usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.text+0xc4): In 
function `__do_global_ctors':
: undefined reference to `__CTOR_LIST__'
/usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.data+0x0): 
undefined reference to `__DTOR_LIST__'

When I run the command with libc:

arm-elf-ld -v -g -O0 -T ld_flash.cmd -o main.elf crt.o main.o 
-L/usr/local/lib/gcc-lib/arm-elf/2.95.3 -L/usr/local/arm-elf/lib/ -lc

I get:
main.o(.text+0x1e0): In function `main':
home.../ArmPrj/main.c:153: undefined reference to `__gccmain'


@ skriptkiddy, Nice to hear, if I don't get this to work I will also try 
Codesourcery ARM 2011.03. Could you please run:
arm-elf-gcc -S main.c -o main.s
and attach the assembler file here. I have detected a strange line in my 
assembler file:
bl __gccmain
Which stands for branch to the label __gccmain, but there isn't any 
label named __gccmain and I can't see the reason why there is a branch 
there at all.

/Dan

von (unknown) (Guest)


Rate this post
0 useful
not useful
I found the solution at:
http://www.embedinfo.com/en/FAQ/FAQanswer.asp?id=19

The problem could simply be solved by changing the name of int main() to 
int _gccmain().

/Dan

von Name: (Guest)


Rate this post
0 useful
not useful
Usually it´s better to use the gcc command also for linking as it takes 
care for the correct libs, unlike the ld command which requires the libs 
to be specified explicitely.

von (unknown) (Guest)


Rate this post
0 useful
not useful
Do you mean the arm-elf-gcc instead of the arm-elf-ld command? I still 
get an error when I am running:

arm-elf-gcc -v -g -O0 -T ld_flash.cmd -o main.elf crt.o main.o



The output is:

/usr/local/lib/gcc-lib/arm-elf/2.95.3/collect2 -X -o main.elf 
/usr/local/arm-elf/lib/crt0.o -L/usr/local/lib/gcc-lib/arm-elf/2.95.3 
-L/usr/local/arm-elf/lib crt.o main.o -lgcc -lg -lc -lgcc -T 
ld_flash.cmd
/usr/local/arm-elf/bin/ld.real: warning: no memory region specified for 
section `.note.ABI-tag'
/usr/local/arm-elf/bin/ld.real: section .note.ABI-tag [00000000 -> 
0000001f] overlaps section .text [00000000 -> 00001e3b]
/usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.text+0xc4): In 
function `__do_global_ctors':
: undefined reference to `__CTOR_LIST__'
/usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.data+0x0): 
undefined reference to `__DTOR_LIST__

/Dan

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.