Reduce exe file

后端 未结 5 1156
失恋的感觉
失恋的感觉 2020-12-07 18:09

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?
(

5条回答
  •  感动是毒
    2020-12-07 18:50

    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!

提交回复
热议问题