compiled code file size

Duke Normandin dukeofperl at ml1.net
Fri Sep 20 15:52:57 PDT 2013


On Friday, 20-Sep-13 2:20 PM, H. S. Teoh wrote:
> 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.)

Thx!  I'll have to do some experimenting ...



More information about the Digitalmars-d mailing list