help-gplusplus
[Top][All Lists]
Advanced

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

Re: questions about link


From: Paul Pluzhnikov
Subject: Re: questions about link
Date: Wed, 17 Jan 2007 22:44:29 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

Chameleon <cham_gss@hotmail.com> writes:

> So the question is why linker include useless binary objects to final
> binary executable.

Because you told it to do so.

When you link with 

  g++ main.o foo.o bar.o baz.o -laaa -lbbb -lccc

then linker is *not allowed* to remove foo.o, bar.o and baz.o from
the link [1]. Contrast this with:

  ar ruv libfoobarbaz.a foo.o bar.o baz.o
  g++ main.o -lfoobarbaz -laaa -lbbb -lccc

Now the linker can remove foo.o etc. from the link if they are not
referenced by main.o

More info here: http://webpages.charter.net/ppluzhnikov/linker.html

Cheers,

[1] Some linkers (most notably AIX) ignore what you *explicitly*
told them to do, and do what they think is "right". Quite often what
they think is "right" is actually wrong, and tools that think they
are smarter than the programmer are the first ones to be against
the wall when the revolution comes.
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

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