Re: Downloaded Bloodshed devcpp, compiled the Hello example but the exe is half a megabyte!?
On Oct 29, 4:07 am, "Dave -Turner" <n...@no.no> wrote:
So I just downloaded Bloodshed devcpp, opened up the Hello
example, compiled it, no problems ..... well, except one - the
exe is 474,990 bytes! What's the secret to compiling small
exes?
Getting the compiler and linker options right:-). It all
depends on the compiler, and also what you mean by the size of
the executable (file size, or what the command size says), but
all systems I've used have options controlling the amount of
debug information (symbols, etc) left in the executable, and
most also have options for linking more or less of the standard
library dynamically. Strip all of your symbols, and link
everything dynamically, and the resulting executable shouldn't
be too big. Thus, for example, with g++ on a Sparc, one simple
C++ version of hello world is 7.7KB when the libraries are
dynamically linked, but more than 3 MB when everything is linked
statically.
Be careful about this, though. File size is rarely that
important, and if you link dynamically, you have to ensure that
the necessary dll or so are present on the target machine where
the code is to run. And if you link statically, you have to
ensure that the version of the library you link is compatible
with the OS on the target machine. Under Unix, for example, I
generally link everything but the system libraries (libc, libm,
etc.) statically---the system libraries are bundled with the
system (and so sure to be present on all machines running the
OS), and tend not to be compatible between versions of the OS.
Under Windows, I'd statically link the system libraries as well,
since they aren't bundled (and individual versions do seem to
work under different versions of the OS). This results in much
larger executable files, but 1) all I have to do to install the
program so that it works is copy the single, executable file,
and 2) the versions of the library which I tested are the same
as those which the user uses. For third party libraries, you'll
want to decide on a per library basis: licensing issues will
frequently require the library to be present on the target
system anyway, and using dynamic linking may allow upgrading the
version (e.g. of the database) without requiring a new
deployment of your software.
Similarly, if you strip symbols, the executable you deliver will
be much smaller, but you'll have a much harder time figuring out
what went wrong if it crashes at the user site. (Again, the
criteria are different for Unix and Windows---Windows doesn't
normally give you a core dump on which you can do a post
mortum, so the lack of symbols may not be a problem.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34