This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Order of .o-files and .a-files
- To: Henrik dot Nilsson at west dot se
- Subject: Re: Order of .o-files and .a-files
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 18 Nov 2000 03:05:47 -0200
- Cc: gcc at gcc dot gnu dot org
- Organization: GCC Team, Red Hat
- References: <200011171054.eAHAsfs27498@mail.west.se>
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