[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] Suggestion for FAQ entry - LD vs. GCC

From: Onno Kortmann
Subject: [avr-libc-dev] Suggestion for FAQ entry - LD vs. GCC
Date: Tue, 29 Mar 2005 22:59:27 +0200
User-agent: KMail/1.7.1


I'm lurking around here for quite a while now.

I have a suggestion for a change in the way avr-ld works or,
if that is not possible/desired a suggestion for a new FAQ entry.
I don't know how often this is asked here, though (so... maybe no FAQ ;).

Ok, here my entry in a FAQ-like format:

- How do I avoid undefined references to __stack and exit?
Linking an AVR program with 'ld' gives an error about an undefined reference 
to __stack. 

If one tries to build an AVR program the usual linux way:

$ avr-gcc -c hello-world.c 
$ avr-ld -o hello-world.elf hello-world.o

an error occurs:

hello-world.o(.text+0x0): In function `main':
: undefined reference to `__stack'
hello-world.o(.text+0x2): In function `main':
: undefined reference to `__stack'
hello-world.o(.text+0xc): In function `main':
: undefined reference to `exit'

This happens because startup code is missing and the linker does not know 
where to find it. But avr-gcc knows. The program links correctly by calling 
avr-gcc like this:
$ avr-gcc -o hello-world.elf hello-world.o

Rationale for this entry:
I feel that it is rather common to build programs in the linux world this way. 
[It works there without explicitely including the startup code in the link]
It did me cost quite some time to figure out that startup code was missing (as 
it seems to be natural to link with ld, but without any options to ld). Also, 
there seem to be several posts about this problem, even on this ML.
And, no, this is not the first time I used avr-gcc, but I used the compiler 
for linking until now (readily available scripts).

If you include it, feel free to edit it as you like - but remove my grammar 
errors :)

BTW: If this is considered a bug, my version of avr-gcc is the newest in 
$ avr-gcc --version
avr-gcc (GCC) 3.4.3
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

Best regards,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]