减少exe文件 [英] Reduce exe file

查看:123
本文介绍了减少exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Delphi(通常,任何工具,如果存在的话),是否可以减少exe文件的大小,删除所有不使用但是存在的代码?

(例如,存在但从未调用的函数或过程)。

我记得使用Pascal,使用单元(没有对象),编译器只包含真正使用的过程和函数,并将删除来自最终exe的单位中的未使用的例程。



使用Object-pascal,我记得在Delphi 1中,一个对象的所有成员都包含在exe中;

自从更改了直到Delphi-XE2?

解决方案

如果您不使用RTTI,可以将其添加到.dpr文件的顶部紧随程序之后),以删除额外的RTTI信息:

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

如果你想把它从所有的RTL / VCL单元中删除,那么你也需要将它们包含在你的项目文件中,以便上面的设置可以影响。我不认为我会推荐这样做,因为我不相信可执行大小的减少值得编译自己的RTL / VCL的复杂性。



你可以还添加以下内容,再次在.dpr文件中的某个地方:

  {$ SetPEFlags IMAGE_FILE_RELOCS_STRIPPED} 

这将剥离.exe中不需要的重定位信息。不要将其添加到DLL或程序包!


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?

解决方案

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!

这篇关于减少exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆