开发者

How can I set the $RTTI directive for the entire project?

开发者 https://www.devze.com 2022-12-16 05:43 出处:网络
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.(O

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 abo开发者_如何学Gout 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...


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).


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...


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消