|
From: Appaiah K. <ana...@ya...> - 2000-12-05 03:02:37
|
Hi friends!
On 30 Nov 2000, at 14:12, bis...@bt...
wrote:
> Hi
>
> I've been using the MingW g++ compiler for compiling C++ programs (both
> console and GUI apps using WxWindows). It seems to me that the executables
> produced by MingW g++ are always very large compared to VC++. For example
> the C++ version of hello (using iostream/cout) produces an executable of
> almost 75K (after stripping) and the minimial WxWin statically linked
> program takes about 1M (again, after stripping) as opposed to around 400K
> using VC++ . C executables are much better.
>
> My questions:
> a) Is this a limitation of the MingW C++ compiler/linker ? I was told by
> someone that it is not good at removing unneeded code - is this true ?
> b) What else can I do (except using compression software) to reduce
> executable size ?
Dear fellow Mingw users,
I have been seeing some discussion about the large executable sizes of
programs compiled using Mingw. I don't know whether you have tried using it,
but Colin Peters' method of linking, used in Jam, a 'make' replacement, is
quite good.
Do I need to tell you, that Colin Peters is the original creator of Mingw32?
Using his linking method, the executable size reduces drastically. Consider
the following code:
#include <stdio.h>
int
main (int argc, char * argv [])
{
printf ("Hi there!\n") ;
return 0 ;
}
Compiling this code using the following command:
gcc -o app.exe test.c
produces an executable whose size is 9465 bytes. But using the following
commands:
gcc -c -o test.o test.c
gcc -s -Wl,--stack,10000 -o app.exe -Wl,--base-file,app.b test.o
dlltool --dllname app.exe --base-file app.b --output-exp app.e
gcc -s -Wl,--stack,10000 -o app.exe -Wl,--base-file,app.b
test.o -Wl,app.e
dlltool --dllname app.exe --base-file app.b --output-exp app.e
gcc -s -Wl,--stack,10000 -o app.exe test.o -Wl,app.e
rm app.b
rm app.e
results with an executable of only 3584 bytes. This method also applies for
larger code as well as C++ code. Actually, it adds relocation information to
the code and can also be used to create relocatable DLLs.
If you think all the code given above is in Greek and Latin, this is
how Colin Peters describes it:
"This odd link action builds an executable with relocation information
and can also be used to build DLLs. Unpleasantly complex, but there it
is. The first pass with the linker and dlltool create an exports file
(_temp.exp) containing the base relocations (written into _temp.base)
by the linker) and possibly exports in a .def file if the DLLTOOLFLAGS
contains a --def option. The second pass rebuilds the relocations to
compensate for including the exports file into the executable
(relocations
may be invalidated by exports), and produces a new exports file with the
proper relocations. Then, finally, the actual executable or dll is
linked
with the exports file."
If you want to learn more about Jam, the project building tool I use, please
visit Colin Peters' website:
http://www.geocities.com/Tokyo/Towers/6162/
The Jam available there is actually a version customized (read stripped
down) for Mingw32.
Please do comment on what I have mentioned here.
Yours sincerely,
A.Kumar
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
|