如何为整个项目设置 $RTTI 指令?

发布于 2024-08-18 15:07:21 字数 404 浏览 7 评论 0原文

我正在将一个旧项目从 Delphi 2007 迁移到 Delphi 2010。我发现生成的可执行文件的大小增加了一倍多,而原始项目已经相当大了。 (超过 50 MB。)我怀疑其中很大一部分与扩展 RTTI 有关。

由于该项目早于 Delphi 2010,因此它在任何地方都没有使用扩展 RTTI,因此我想保守地包含它。有没有办法使用“项目选项”对话框将 {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} 全局设置为默认值?我本以为在某个地方会有一个选项(以及 $WEAKLINKRTTI),但我没有看到它们。

有谁知道这是否可以通过“传递给编译器的其他选项”字段或其他方式来完成?我真的不想向项目中的每个单元添加包含文件,因为它们有几千个......

I'm working on migrating an old project from Delphi 2007 to Delphi 2010. One thing I've found is that the resulting executable has more than doubled in size, and the original was already quite big. (Over 50 MB.) I suspect that a lot of it has to do with extended RTTI.

Since the project predates Delphi 2010, it doesn't use extended RTTI anywhere, and I'd like to be conservative about including it. Is there any way to use the Project Options dialog to globally set {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} as the default? I'd have expected there to be an option for this (and for $WEAKLINKRTTI) somewhere, but I don't see them.

Does anyone know if this can be done from the "Additional options to pass to the compiler" field, or some other way? I'd really prefer not to have to add an include file to every single unit in the project, as there are a few thousand of them...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

枕头说它不想醒 2024-08-25 15:07:21

自 XE6 以来,$RTTI 指令的行为已发生更改,因为实际上它是一个 bug< /a> 因为它应该是当前单元的本地(实际上是 自 Delphi 2010 以来就有记录)。

此外,即使在一个单元中使用该指令也可能会产生致命的影响,因为由于该错误,它基本上切换了一个影响后续单元的全局标志(如编译顺序所示)。

The behavior of the $RTTI directive has been changed since XE6 because actually it was a bug because it was supposed to be local to the current unit (and it was actually documented as that since Delphi 2010).

Also it could have fatal affects using the directive at all even in one unit because due to the bug it basically switched a global flag affecting the following units (as in the order of compilation).

窗影残 2024-08-25 15:07:21

对 Mason 自己的博客的评论中,在回应我的评论时,梅森回答了这个问题。

尝试将这两行放在顶部
您的 DPR,在 USES 子句之前:

<前><代码>{$WEAKLINKRTTI ON}
{$RTTI 显式方法([]) 属性([]) 字段([])}

这将确保没有 RTTI 得到
为您自己的代码或任何代码生成
您使用的第三方库,除非
他们在 RTTI 所在的单位
生成已明确启用。你
无法针对 RTL 或 VCL 将其关闭,
但这不会增加太多
无论如何,你的尺寸。

In a comment on Mason's own blog, in response to a comment of mine, Mason answered this question.

Try putting these two lines at the top
of your DPR, before the USES clause:

{$WEAKLINKRTTI ON}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}

This will make sure that no RTTI gets
generated for your own code or any
third-party libraries you use, unless
they’re in a unit where RTTI
generation is explicitly enabled. You
can’t turn it off for the RTL or VCL,
but that shouldn’t add very much to
your size anyway.

傾旎 2024-08-25 15:07:21

您可以尝试使用 dcc32 –$weaklinkrtti 命令行选项。 (如{$WEAKLINKRTTI ON})。
但这并没有影响每个单元中的 {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
最好的选择是将其放在包含文件中每个单元的顶部。
但对于 VCL/RTL 来说它就不行了,它仍然会膨胀……

更新:还要确保你比较了可比的内容。例如,验证是否在新的 D2010 项目的链接器选项中不包含调试信息,而在 D2007 项目中可能没有该信息...

You can try with the dcc32 –$weaklinkrtti command-line option. (like {$WEAKLINKRTTI ON}).
But that has not the impact of {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} in each unit.
Your best bet would be to have it at the top of each unit in an include file.
But then it wouldn't do it for the VCL/RTL which would still be inflated....

Update: Also make sure you compare what's comparable. For instance verify if you don't include debug information in the Linker Options in the new D2010 project where you may not have it in the D2007 one...

那伤。 2024-08-25 15:07:21

您确定这是由新的 RTTI 信息引起的吗?虽然数据量很大,但它实际上不应该使应用程序的大小增加一倍。

检查它是否在发布版本可执行文件中包含调试信息。
(项目选项 -> Delphi 编译器 -> 调试信息应该为 False)

至于问题,我在 dpr 文件中的 use 子句之前使用 {$WEAKLINKRTTI ON} ,它似乎工作正常。

Are you certain this is caused by the new RTTI info? While it's a lot of data it shouldn't really double the size of your application.

Check that it's not including debug info in the release build executable.
(Project options -> Delphi Compiler -> Debug information should be False)

As for the question, I use {$WEAKLINKRTTI ON} before the uses clause in the dpr file and it seems to work fine.

遇到 2024-08-25 15:07:21

我不知道有这样的选项,但我仍然会使用包含文件。

对于任何有经验的 Delphi 程序员来说,编写一个小程序将 {$i ProjectIncludeFile.inc} 添加到文件夹中的任何单元(紧接在单元行之后)都不会成为问题。

这样你就可以将它用于你喜欢的任何目的。

我自己使用 if fi 设置一个 WriteTempFiles 编译器指令(在开发程序时,我使用 fi 在各个位置保存字符串列表内容),这样我可以在程序准备好时在一个地方禁用它用于部署。

由于我的大多数项目都涉及多个可执行文件和/或 dll,因此这是在整个项目中全局完成此操作的最简单方法。

I don't know of such an option, but I still would use an include file.

I wont be a problem for any experienced Delphi programmer to write a small program to add an {$i ProjectIncludeFile.inc} to any unit in your folders (immediatly after the unit line).

And that way you can use it for whatever purpose you like.

I myself use if f.i. to set a WriteTempFiles compiler directive (which I use f.i. to save stringlist contents at various places when developing the program), that way I can disable it in one place when the program is ready for deployment.

Since most of my projects involve multiple executables and/or dll's, this is the easiest way to accomplish this globaly for the whole project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文