Big executable?

Anders F Björklund afb at algonet.se
Wed Oct 6 01:31:19 PDT 2010


Andre Tampubolon wrote:
> I compiled this simple code using DMD 2.049 (dmd -O -release test1.d) :
> import std.stdio;
> 
> void main()
> {
>     writefln("%s World", "Hello");
> }
> 
> The final executable size is about 300 KB. Isn't that a bit huge, 
> considering the same code compiled using C or Pascal compiler will give 
> smaller executable? So I tried to look at the *.map, and apparently the 
> D runtime pulls a lot of stuff. I am just wondering, anyway.

A better size comparison would be with C++ and a static libstdc++:

ln -s `g++ -print-file-name=libstdc++.a`
g++ -O2 -o hello-cxx -static-libgcc -L. hello.cpp

Using GDC instead, no 64-bit DMD (avoiding libgcc_s.so, to compare):

# gdmd -O -release -ofhello-d hello.d
gdc -O2 -frelease -o hello-d -static-libgcc hello.d

540K    hello-cxx
312K    hello-d

And yes it is big, for the trivial example.

gcc -O2 -o hello-c hello.c

12K     hello-c
4,0K    hello.sh

--anders


PS. Static libgcc isn't really a good idea as it breaks exceptions.
It was more for the size comparisons. A dynamic Phobos would "fix".

And yes, those were the sizes without the debugging symbols. Except
that the shell script really was 30 bytes... "strip -S", "du -h".


More information about the Digitalmars-d mailing list