Connecting Tech Pros Worldwide Forums | Help | Site Map

Size of Exe file

Dot.Hu
Guest
 
Posts: n/a
#1: Nov 20 '08
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.

Maxim Yegorushkin
Guest
 
Posts: n/a
#2: Nov 20 '08

re: Size of Exe file


On Nov 20, 6:35*am, "Dot.Hu" <huhang...@gmail.comwrote:
Quote:
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
Guest
 
Posts: n/a
#3: Nov 21 '08

re: Size of Exe file


On Nov 20, 6:33*pm, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
Quote:
On Nov 20, 6:35*am, "Dot.Hu" <huhang...@gmail.comwrote:
>
Quote:
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
Guest
 
Posts: n/a
#4: Nov 21 '08

re: Size of Exe file


Thanks very much, Max.
Quote:
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.
Quote:
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.


Closed Thread