Connecting Tech Pros Worldwide Help | Site Map

Size of Exe file

  #1  
Old November 20th, 2008, 06:45 AM
Dot.Hu
Guest
 
Posts: n/a
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.
  #2  
Old November 20th, 2008, 10:35 AM
Maxim Yegorushkin
Guest
 
Posts: n/a

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
  #3  
Old November 21st, 2008, 05:45 PM
Dot.Hu
Guest
 
Posts: n/a

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.
  #4  
Old November 21st, 2008, 11:35 PM
Thomas Beckmann
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge EXE file size anandsoni@gmail.com answers 2 August 21st, 2007 08:15 PM
How can I decrease size of mem usage. Jesper, Denmark answers 3 November 10th, 2006 06:45 PM
How to get size of file on server? ViRtUaLpCwHiZ answers 2 November 22nd, 2005 05:07 PM
How to get size of file on server? ViRtUaLpCwHiZ answers 2 July 21st, 2005 09:09 PM