* compiled program too big
@ 2003-06-30 8:22 Insanely Great
2003-06-30 8:31 ` Rupert Wood
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Insanely Great @ 2003-06-30 8:22 UTC (permalink / raw)
To: gcc-help
Greetings
I am complete newbie to the world of programming.
Write my first console program which is around 11KB.
basically it takes a string as a first parameter and
does some stupid processing to it.
Works both in VC++ 6.0 in windows and gcc in RH Linux
7.2
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++.
sorry for my ignorance and thanks in advance.
insane
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: compiled program too big
2003-06-30 8:22 compiled program too big Insanely Great
@ 2003-06-30 8:31 ` Rupert Wood
2003-06-30 9:44 ` Mihnea Balta
2003-06-30 16:18 ` Andrea 'fwyzard' Bocci
2 siblings, 0 replies; 4+ messages in thread
From: Rupert Wood @ 2003-06-30 8:31 UTC (permalink / raw)
To: 'Insanely Great'; +Cc: gcc-help
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: compiled program too big
2003-06-30 8:22 compiled program too big Insanely Great
2003-06-30 8:31 ` Rupert Wood
@ 2003-06-30 9:44 ` Mihnea Balta
2003-06-30 16:18 ` Andrea 'fwyzard' Bocci
2 siblings, 0 replies; 4+ messages in thread
From: Mihnea Balta @ 2003-06-30 9:44 UTC (permalink / raw)
To: Insanely Great, gcc-help
Try using this:
g++ -fno-exceptions -O2 First.cpp -Xlinker --strip-all
My results on a 2-line .cpp source:
[11:32am]/tmp# g++ -O2 test.cpp
[11:32am]/tmp# ls a.out
-rwxr-xr-x 1 root root 11161 Jun 30 11:32 a.out
[11:32am]/tmp# g++ -fno-exceptions -O2 test.cpp -Xlinker --strip-all
[11:32am]/tmp# ls a.out
-rwxr-xr-x 1 root root 2572 Jun 30 11:32 a.out
On Monday 30 June 2003 11:01, Insanely Great wrote:
> Greetings
>
> I am complete newbie to the world of programming.
> Write my first console program which is around 11KB.
> basically it takes a string as a first parameter and
> does some stupid processing to it.
>
> Works both in VC++ 6.0 in windows and gcc in RH Linux
> 7.2
>
> 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++.
>
> sorry for my ignorance and thanks in advance.
>
> insane
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
> ---------------------------------------------------------------------------
>-- Gaseste-ti perechea si castiga o saptamana la Poiana -
> http://dating.acasa.ro
-----------------------------------------------------------------------------
Gaseste-ti perechea si castiga o saptamana la Poiana - http://dating.acasa.ro
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: compiled program too big
2003-06-30 8:22 compiled program too big Insanely Great
2003-06-30 8:31 ` Rupert Wood
2003-06-30 9:44 ` Mihnea Balta
@ 2003-06-30 16:18 ` Andrea 'fwyzard' Bocci
2 siblings, 0 replies; 4+ messages in thread
From: Andrea 'fwyzard' Bocci @ 2003-06-30 16:18 UTC (permalink / raw)
To: Insanely Great; +Cc: gcc-help
At 01.01 30/06/2003 -0700, Insanely Great wrote:
>Greetings
>
>I am complete newbie to the world of programming.
>Write my first console program which is around 11KB.
>basically it takes a string as a first parameter and
>does some stupid processing to it.
>
>Works both in VC++ 6.0 in windows and gcc in RH Linux
>7.2
>
>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++.
>
>sorry for my ignorance and thanks in advance.
>
>insane
Try stripping the output executabled:
strip executable_file
This should remove all the sybols from the exe - it halved the size of a
small test program in my cygwin environment, ven when no -g was specified
on command line.
.fwyzard.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-06-30 9:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-30 8:22 compiled program too big Insanely Great
2003-06-30 8:31 ` Rupert Wood
2003-06-30 9:44 ` Mihnea Balta
2003-06-30 16:18 ` Andrea 'fwyzard' Bocci
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).