Order of .o-files and .a-files
Alexandre Oliva
aoliva@redhat.com
Sat Nov 18 04:38:00 GMT 2000
On Nov 17, 2000, Henrik Nilsson <Henrik.Nilsson@west.se> wrote:
> I'm having trouble understanding why the order of certain files is important.
This is a linker issue, not a compiler issue.
The reason why case 2 doesn't work is simple: when you link an object
file into a program, all of its contents make it to the program.
However, when you link a (static) library into a program, the linker
only brings into the executable the component object files that define
symbols that are undefined in object files previously linked in.
When you list a library before your object (or source) files, the
linker will only be looking for main() when it searches the library.
Then, it gets to your object file, brings it in, and gets to the end
of the list, noticing there are some symbols whose definitions haven't
been supplied. It won't search previously searched libraries again.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me
More information about the Gcc
mailing list