Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce exe file

Tags:

Using Delphi (or in general any tools, if exist of course), is it possible to reduce size of an exe file, removing all code that not is used but that is present there?
(for example, a function or procedure that is present but is never called).
I remember that with Pascal, using unit (without objects) the compiler includes only procedures and functions that are really used and will strip out non-used routines in a unit from the final exe.

With Object-pascal, I remember that in Delphi 1 all members of a object are included in the exe;
Has something has changed since than till Delphi-XE2?

like image 837
Marcello Impastato Avatar asked Sep 13 '11 07:09

Marcello Impastato


2 Answers

If you aren't using RTTI you can add this to the top of your .dpr file (immediately after program) to remove the extra RTTI information:

{$IFOPT D-}{$WEAKLINKRTTI ON}{$ENDIF}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}

If you want to strip it out of all the RTL/VCL units then you'd need to include those in your project file too so that the settings above could take effect. I don't think I would recommend doing that since I don't believe the reduction in executable size is worth the complications of compiling your own RTL/VCL.

You can also add the following, again somewhere in your .dpr file:

{$SetPEFlags IMAGE_FILE_RELOCS_STRIPPED}

This will strip the relocation information which is not needed in a .exe. Don't add this to a DLL or package!

like image 147
David Heffernan Avatar answered Sep 18 '22 21:09

David Heffernan


reduce the application EXE size - excellent article

(Taken from the link above)

Generally, EXE files created with Delphi are larger than EXE files created with another programming language. The reason is the VCL. (Sure, VCL has many advantages...)

There are several ways to reduce a EXE's size:

01) Use a EXE-Packer (UPX, ASPack,...)-UPX

02) Use KOL.

03) Write your application without VCL

04) Use the ACL (API Controls Library)

05) Use StripReloc.

06) Deactivate remote debugging information and TD32.

07) You might want to put code in a dll.

08) Don't put the same images several times on a form. Load them at runtime.

09) Use compressed images (JPG and not BMP)

10) Store less properties in DFM files

like image 40
RBA Avatar answered Sep 22 '22 21:09

RBA