This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ld: creating a dynamically linked executable ...
- From: John Reiser <jreiser at bitwagon dot com>
- To: binutils at sourceware dot org
- Date: Thu, 11 Jul 2013 08:57:52 -0700
- Subject: Re: ld: creating a dynamically linked executable ...
- References: <CABzSAw81DSh1OOnKrQk+XTKVrMqMdJXmx2sS1_3MCm-6nWKd8g at mail dot gmail dot com> <CABzSAw8j56ioPMc_Osjt_JV6FWwFL=KXfGwMKKnpUb5hwfu9yg at mail dot gmail dot com>
> $> gcc -o use-of-lib use-of-lib.o
> use-of-lib.o: In function `_start':
> (.text+0x0): multiple definition of `_start'
> /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info):
> relocation 0 has invalid symbol index 11
<<snip>>
> /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:/build/buildd/eglibc-2.15/csu/../sysdeps/i386/elf/start.S:119:
> first defined here
> /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In
> function `_start':
> (.text+0x18): undefined reference to `main'
> collect2: ld returned 1 exit status
use-of-lib.s has:
.global _start
_start:
When using gcc to perform static linking then the crt*.o routines define _start,
so your _start conflicts. Use 'main' instead. Also do "gcc -S hello.c"
(where hello.c is the obvious program which prints "Hello, world!\n")
then look at hello.s. [In general: when trying a new thing, then search
for previous examples which are related, and see what you can learn
from the similarities and from the differences.]