compiled code file size

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Sep 20 13:20:25 PDT 2013


On Fri, Sep 20, 2013 at 11:26:18AM -0600, Duke Normandin wrote:
> On Friday, 20-Sep-13 10:45 AM, Adam D. Ruppe wrote:
> >On Friday, 20 September 2013 at 16:20:34 UTC, Duke Normandin wrote:
> >>Why such a huge difference???
> >
> >The D program carries its additional D runtime library code with it,
> >whereas the C program only depends on libraries provided by the
> >operating system, and thus it doesn't have to include it in the exe.
> 
> Now that I know _why_ , is there a way to shave tons off those
> executables? Any optimization possible?

If you're on Linux:

	dmd -release -O myprogram.d
	strip myprogram
	upx myprogram

I've seen this reduce a 50MB executable down to about 400k. YMMV.

Keep in mind, though, that stripping basically deletes all debugging
information from the executable (plus a bunch of other stuff -- you
don't want to do this to an object file or a library, for example), so
it's not something you want to do during development. And upx turns your
executable into something that probably violates the ELF spec in many
different ways, but resembles it closely enough that the kernel will
still run it. File type recognizers like 'file' may fail to recognize
the result as an executable afterwards. But it will still work. (That's
how cool upx is, in case you don't already know that.)


T

-- 
The right half of the brain controls the left half of the body. This means that only left-handed people are in their right mind. -- Manoj Srivastava


More information about the Digitalmars-d mailing list