arm-elf-ld problem, undefined reference to `__gccmain'

OP Guest #2779221
Rate this post
• ▲ 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
Attached files:
OP Guest #2781426
Rate this post
• ▲ 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
OP Guest #2781467
Rate this post
• ▲ 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

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.