This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: compiled program too big


Insanely Great wrote: 

> The problem is when I comile with VC++ in Release mode the output
> exe is 44KB.
>
> when i comile the same program in linux using gcc -
> 
> gcc -O2 First.cpp
> 
> the resulting program is 126KB....why? am i missing some option.
> 
> is there any option to tell gcc to compile it in something like
> RELEASE MODE in VC++.

Hmm - you pretty much already are.

First up, comparing binary sizes between different compilers' default
options and different OSes is bogus. Some compilers (e.g. MSVC) default to
statically linking in C and C++ runtimes, automatically align pages at 4Kb
boundaries on disk for simpler cache management, single thread vs.
multi-thread-safe runtime, etc. (If people start complaining that MSVC makes
exes too big vs. gcc on linux I usually recommend they try flags '/MD /link
/align:16' to put them on a more equal footing - but that's usually because
the MSVC binaries are bigger!)

VC++'s release mode just means:

   1. use 'release' runtime, i.e. skip debugging checks in the
      runtime libraries for improved speed (and binary size
      if you're statically linking runtime); I don't think
      linux build environments have an equivalent to the debug
      runtime - that's easily switchable, at least

   2. optimize the code; -O2 is about equivalent to this

   3. don't include debug information in the binary; omitting
      -g from the GCC command line is equivalent to this.

so essentially you're already in release mode with your -O2. The other major
variable is the static / dynamic runtime library link; it's probably a
fairer comparison if you make sure both are linked against shared runtime
('-shared' in GCC, '/MD' on the VC++ command line, select DLL under Project
Settings, C++, Code Generation or similar in developer studio).

My final thought is that you've somehow not enabled dead code elimination in
GCC; thanks to the new, more strictly conforming templates in GCC this can
make a huge difference. I thought -O2 did enable DCE but you could try -O3
or check the manual to see if there's a specific switch - it's not one I've
used, sorry.

Good luck!
Rup.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]