www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - why simple hello world binary is ~700KB

reply Bedros Hanounik <2bedros NOSPAMgmail.com> writes:
why when I compile this program under gdc I get 697KB of binary and when I
compile similar C code in gcc I get 6.5KB (both under Linux (GCC) 4.1.2
20070214 (  (gdc 0.24, using dmd 1.020))



import std.stdio;

int main ()
{
	writefln("Hello World!");
	    return 0;
}

how can I get small footprint binaries out of any D compiler? any difference
between gdc and dmd?
Oct 04 2007
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Bedros,

 why when I compile this program under gdc I get 697KB of binary and
 when I compile similar C code in gcc I get 6.5KB (both under Linux
 (GCC) 4.1.2 20070214 (  (gdc 0.24, using dmd 1.020))
 
 import std.stdio;
 
 int main ()
 {
 writefln("Hello World!");
 return 0;
 }
 how can I get small footprint binaries out of any D compiler? any
 difference between gdc and dmd?
 
short version: D doesn't (yet) use shared objects for the stdlib, C does. At this point, that hello world has most of the stdlib in it. This issue has been brought up before and something will get done about it sooner or later.
Oct 04 2007
parent reply Michael Gnail <gnail.f gmail.com> writes:
BCS wrote:
 Reply to Bedros,
 
 why when I compile this program under gdc I get 697KB of binary and
 when I compile similar C code in gcc I get 6.5KB (both under Linux
 (GCC) 4.1.2 20070214 (  (gdc 0.24, using dmd 1.020))

 import std.stdio;

 int main ()
 {
 writefln("Hello World!");
 return 0;
 }
 how can I get small footprint binaries out of any D compiler? any
 difference between gdc and dmd?
short version: D doesn't (yet) use shared objects for the stdlib, C does. At this point, that hello world has most of the stdlib in it. This issue has been brought up before and something will get done about it sooner or later.
I got a near 110K 'hello,world' on my XP with D 1.015, will there any way to link only the used part of stdlib in future version?
Oct 05 2007
parent BCS <ao pathlink.com> writes:
Reply to Michael,

 BCS wrote:
 
 Reply to Bedros,
 
 why when I compile this program under gdc I get 697KB of binary and
 when I compile similar C code in gcc I get 6.5KB (both under Linux
 (GCC) 4.1.2 20070214 (  (gdc 0.24, using dmd 1.020))
 
 import std.stdio;
 
 int main ()
 {
 writefln("Hello World!");
 return 0;
 }
 how can I get small footprint binaries out of any D compiler? any
 difference between gdc and dmd?
short version: D doesn't (yet) use shared objects for the stdlib, C does. At this point, that hello world has most of the stdlib in it. This issue has been brought up before and something will get done about it sooner or later.
I got a near 110K 'hello,world' on my XP with D 1.015, will there any way to link only the used part of stdlib in future version?
IIRC that is a linker issue. Tango side steps it by putting next to nothing in the lib and lets you compile just about everthing and then just link in the modules you use.
Oct 05 2007
prev sibling next sibling parent reply Gregor Richards <Richards codu.org> writes:
Bedros Hanounik wrote:
 why when I compile this program under gdc I get 697KB of binary and when I
compile similar C code in gcc I get 6.5KB (both under Linux (GCC) 4.1.2
20070214 (  (gdc 0.24, using dmd 1.020))
 
 
 
 import std.stdio;
 
 int main ()
 {
 	writefln("Hello World!");
 	    return 0;
 }
 
 how can I get small footprint binaries out of any D compiler? any difference
between gdc and dmd?
 
 
As per usual, the person asking this has not stripped his binary. How do so many people continue to labor under the misconception that no extra info is added to the binary by default? Strip your binaries. - Gregor Richards
Oct 04 2007
parent "Simen Haugen" <simen norstat.no> writes:
"Gregor Richards" <Richards codu.org> wrote in message 
news:fe3opi$n0o$1 digitalmars.com...
 As per usual, the person asking this has not stripped his binary. How do 
 so many people continue to labor under the misconception that no extra 
 info is added to the binary by default?

 Strip your binaries.
Is there a strip utility for dmd produced .exe files? If I try to use gnu strip i get "\temp\t.exe: File format not recognized" A test with dmd 1.021 makes hello world 113kb, and after upx 49kb. Of course, a simple C version is 16kb and 13kb after upx. I'd still prefer D over C :)
Oct 05 2007
prev sibling next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Bedros Hanounik" <2bedros NOSPAMgmail.com> wrote in message 
news:fe3itj$eks$1 digitalmars.com...
 why when I compile this program under gdc I get 697KB of binary and when I 
 compile similar C code in gcc I get 6.5KB (both under Linux (GCC) 4.1.2 
 20070214 (  (gdc 0.24, using dmd 1.020))



 import std.stdio;

 int main ()
 {
 writefln("Hello World!");
     return 0;
 }

 how can I get small footprint binaries out of any D compiler? any 
 difference between gdc and dmd?
What command line did you use?. Non-release builds can be significantly larger than their release counterparts.
Oct 04 2007
prev sibling parent Jascha Wetzel <firstname mainia.de> writes:
Bedros Hanounik wrote:
 why when I compile this program under gdc I get 697KB of binary and when I
compile similar C code in gcc I get 6.5KB (both under Linux (GCC) 4.1.2
20070214 (  (gdc 0.24, using dmd 1.020))
The comparison isn't quite fair, since the D executable contains a lot more than the C exe does. To get a more realistic comparison, compile a C++ version (using iostream) with statically linked runtime and RTTI enabled. Using VC8 (default release settings, plus /MT for statically linked runtime) that results in an exe size of 108kb, which is comparable to the 113kb that DMD 1.021 produces.
Oct 05 2007