[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Size of Exe file

Dot.Hu

11/20/2008 6:36:00 AM

I'm using static libraries and dynamic libraries every day.
Now I want to know when I add one static library into my project, the
libray will be all added into the final exe file, or only the part I
use is added?
Internet linkes or relative reference books are appreciated.
Thanks.
8 Answers

Maxim Yegorushkin

11/20/2008 10:34:00 AM

0

On Nov 20, 6:35 am, "Dot.Hu" <huhang...@gmail.com> wrote:
> I'm using static libraries and dynamic libraries every day.
> Now I want to know when I add one static library into my project, the
> libray will be all added into the final exe file, or only the part I
> use is added?

A .lib file is basically an archive of .o/.obj files. The linker links
in only those .obj files from the archive that define the symbols that
are unresolved in the binary being linked. In other words, if you link
against a .lib, but the binary being link does not use any of the
symbols from the .lib, that .lib is not contributing to the size of
the resulting binary.

--
Max

Dot.Hu

11/21/2008 5:42:00 PM

0

On Nov 20, 6:33 pm, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
> On Nov 20, 6:35 am, "Dot.Hu" <huhang...@gmail.com> wrote:
>
> > I'm using static libraries and dynamic libraries every day.
> > Now I want to know when I add one static library into my project, the
> > libray will be all added into the final exe file, or only the part I
> > use is added?
>
> A .lib file is basically an archive of .o/.obj files. The linker links
> in only those .obj files from the archive that define the symbols that
> are unresolved in the binary being linked. In other words, if you link
> against a .lib, but the binary being link does not use any of the
> symbols from the .lib, that .lib is not contributing to the size of
> the resulting binary.
>
> --
> Max

Thanks very much, Max.
I got another question.
Once one symbol is used of one .lib, then the whole .lib will be
linked into the exe?

Now I want to create some libraries, where my useful codes will
reside.
But I don't want to increase the size of .exe, because of some unused
symbols.
That's why I post this question.

Thomas Beckmann

11/21/2008 11:35:00 PM

0

> Thanks very much, Max.
> I got another question.
> Once one symbol is used of one .lib, then the whole .lib will be
> linked into the exe?

No, as Max mentionen the .lib is an archive of .obj files. The linker will
select only the subset of object files in the lib that contain symbols
referenced. Thus, unused object files will automatically be thrown away and
do not contribute to the resulting executable.

Thus, in some situation i.e. embedded development it may be worthwhile to
think about the distribution of functions to implementation (.cpp) files.

> Now I want to create some libraries, where my useful codes will
> reside.
> But I don't want to increase the size of .exe, because of some unused
> symbols.
> That's why I post this question.

If you have a newer compiler chances are there is some function-level
linking option that allows the linker to on a per-function basis rather the
object files. On VC++ link-time code generation will strip the resulting
executable even further.

Regards,
Thomas.


Dot.Hu

11/22/2008 3:27:00 AM

0

On Nov 22, 7:34 am, "Thomas Beckmann" <ka6552-...@online.de> wrote:
> > Thanks very much, Max.
> > I got another question.
> > Once one symbol is used of one .lib, then the whole .lib will be
> > linked into the exe?
>
> No, as Max mentionen the .lib is an archive of .obj files. The linker will
> select only the subset of object files in the lib that contain symbols
> referenced. Thus, unused object files will automatically be thrown away and
> do not contribute to the resulting executable.
>
> Thus, in some situation i.e. embedded development it may be worthwhile to
> think about the distribution of functions to implementation (.cpp) files.
>
> > Now I want to create some libraries, where my useful codes will
> > reside.
> > But I don't want to increase the size of .exe, because of some unused
> > symbols.
> > That's why I post this question.
>
> If you have a newer compiler chances are there is some function-level
> linking option that allows the linker to on a per-function basis rather the
> object files. On VC++ link-time code generation will strip the resulting
> executable even further.
>
> Regards,
>     Thomas.

Thank you, Thomas.
It's clear now.
One more question, how did you got to know these?
Are there some relative books or websites? So I can learn more rather
than know the basis.

Thomas Beckmann

11/22/2008 12:38:00 PM

0

> Thank you, Thomas.
> It's clear now.
> One more question, how did you got to know these?
> Are there some relative books or websites? So I can learn more rather
> than know the basis.

Hard to say where I read these. I recall this was an important topic in the
late 90s, guess the MSDN magazine had an article or two on the topic. Their
website has an archive. Also, http://w... is a great source of
information and certainly the Exceptional C++ series of Sutter I can
recommend.


Dot.Hu

11/22/2008 3:44:00 PM

0

On Nov 22, 8:38 pm, "Thomas Beckmann" <ka6552-...@online.de> wrote:
> > Thank you, Thomas.
> > It's clear now.
> > One more question, how did you got to know these?
> > Are there some relative books or websites? So I can learn more rather
> > than know the basis.
>
> Hard to say where I read these. I recall this was an important topic in the
> late 90s, guess the MSDN magazine had an article or two on the topic. Their
> website has an archive. Also,http://www... a great source of
> information and certainly the Exceptional C++ series of Sutter I can
> recommend.

OK, thanks very much.

Jorgen Grahn

11/22/2008 11:47:00 PM

0

On Sat, 22 Nov 2008 13:38:21 +0100, Thomas Beckmann <ka6552-360@online.de> wrote:
>> Thank you, Thomas.
>> It's clear now.
>> One more question, how did you got to know these?
>> Are there some relative books or websites? So I can learn more rather
>> than know the basis.
>
> Hard to say where I read these. I recall this was an important topic in the
> late 90s, guess the MSDN magazine had an article or two on the topic. Their
> website has an archive. Also, http://w... is a great source of
> information and certainly the Exceptional C++ series of Sutter I can
> recommend.

On my system, the linker's documentation (not surprisingly) documents
this.

Just to be clear: it's a feature of the compiler/linker, not the C++
language. I can imagine linkers which just pulls in the needed parts
out of the object files, in turned pulled from the archives. Or
systems without linkers, etc.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!

James Kanze

11/23/2008 11:37:00 AM

0

On Nov 23, 12:46 am, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
> On Sat, 22 Nov 2008 13:38:21 +0100, Thomas Beckmann
> <ka6552-...@online.de> wrote:
> >> Thank you, Thomas.
> >> It's clear now.
> >> One more question, how did you got to know these?
> >> Are there some relative books or websites? So I can learn more rather
> >> than know the basis.

> > Hard to say where I read these. I recall this was an
> > important topic in the late 90s, guess the MSDN magazine had
> > an article or two on the topic. Their website has an
> > archive. Also,http://www... a great source of
> > information and certainly the Exceptional C++ series of
> > Sutter I can recommend.

> On my system, the linker's documentation (not surprisingly)
> documents this.

Most of the linker documentation I've seen supposes that one
already knows the real basics: what a linker does (in general),
what a library is, etc. If you're really good, you can probably
deduce much of this from the linker documentation, but
typically, I'd hardly call it pedagogical material.

> Just to be clear: it's a feature of the compiler/linker, not
> the C++ language.  I can imagine linkers which just pulls in
> the needed parts out of the object files, in turned pulled
> from the archives. Or systems without linkers, etc.

Yes and no. The standard does say at one point (phases of
compilation, phase 9) that "All external object and function
references are resolved. Library components are linked to
satisfy external references to functions and objects not defined
in the current translation. All such translator output is
collected into a program image which contains information needed
for execution in its execution environment." Which sounds
pretty much like a linker to me. And there are generally
established definitions, independently of the implementation (so
under Windows, a DLL is a type of object file, and not a
library, despite its name); the question per se isn't
implementation specific, even if a really detailed answer will
involve some implementation specific details.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34