[ale] gcc errors...
Omar Loggiodice
ologgio at vrainn.com
Thu Aug 29 23:09:57 EDT 1996
nomad Writes :
:I can do a "gcc compile.c" and it does everything beautifully.
:But when I do a "gcc -c compile.c" and "ld compile.c" I get the
:following:
:
:-rw-r--r-- 1 root root 180 Aug 29 21:54 compile.c
:-rw-r--r-- 1 root root 1092 Aug 29 21:56 compile.o
:{0}:oasis:/root/prog/>ld compile.o
:ld: warning: cannot find entry symbol _start; defaulting to 08048074
:compile.o: In function `main':
:compile.o(.text+0xc): undefined reference to `printf'
:compile.o(.text+0x19): undefined reference to `printf'
:compile.o(.text+0x26): undefined reference to `printf'
:compile.o(.text+0x37): undefined reference to `scanf'
:compile.o(.text+0x44): undefined reference to `printf'
:compile.o(.text+0x55): undefined reference to `printf'
:
To form an executable from your object file, ld needs to resolve several
symbols (such as printf and _start). Obviously those two are not defined
in your object file, so the linker complains and says that it doesn't know
where to find them (BTW, _start is an implicit initialization
routine that is called automatically).
If you wanted to link your program separately the best way to do it is to
do:
gcc -o myexecutable mysource.c
This calls the linker with the appropiate flags and libraries.
printf is part of the C library (libc.so.XXXXX) in your machine, and there
are other initialization files that need to be linked in to form an
executable from your object file.
If you want to see the real command that is used to link programs, you
can do:
gcc -v -o h t.o
which will give you an output similar to:
gcc version 2.7.2
/usr/i486-linux/bin/ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.1 -o h
/usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o
-L/usr/lib/gcc-lib/i486-linux/2.7.2 -L/usr/i486-linux/lib t.o -lgcc
-lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o
As you can see there are lots of other things that need to be linked with
your object code to form an executable. (-lc is the c library, the crt* files
are initialization and other needed functions, ld-linux.so is the loader of
dynamic libraries, etc...)
As I said before, the best way to link the code (without compiling) is to call
gcc -o myexe mysource.o...this will take care of calling the linker with the
appropiate flags, paths, object files and libraries for your architecture.
Hope it helps......
--
____________________________________________________________________
/ __ __ __ - __ __ / - _ __ ologgio at vrainn.com
Omar R. /__ /_/ /_/ /_/ / /_/ /_/ / /_ /-_ CIS: 74040,1543
__/ __/
___C++/6_yrs____Virtual Reality/4_yrs____Vorl_____Linux(free)_______
Apple ]['s, remember Applesoft?
More information about the Ale
mailing list