为什么 C++Builder 无法创建预编译头?
问题
在 CodeGear C++Builder 2009 中,我们使用预编译头注入来大大减少编译时间。 我们将相同的头文件注入到多个项目中。 编译某些项目时,编译器会抛出以下警告:
[BCC32 Warning] Dateutils.hpp(43): W8058 Cannot create pre-compiled header: initialized data in header
在此示例中,Dateutils.hpp是它所抱怨的文件(CodeGear 的标头)。 我也曾在其他标头中看到过这种情况。 有趣的是,这种情况只发生在某些项目中(注入相同的标头)。
在过去,我必须找到最终包含此错误文件的标头并将其从预编译的标头文件中删除。 有谁知道这里发生了什么以及解决它的最佳方法?
更新
我最终对头文件执行了消除方法,并得出了一个我无法解释的有趣发现。 在包含的 50 多个标头中,当我删除 vcl.h 时,我不再收到 W8058 警告。 我不明白这一点,因为我认为这个头文件特别是预编译的主要候选者。 谁能解释一下吗?
Problem
In CodeGear C++Builder 2009 we are using the pre-compiled header injection to greatly reduce our compile times. We have the same header file being injected into multiple projects. When compiling some projects, the compiler kicks out the following warning:
[BCC32 Warning] Dateutils.hpp(43): W8058 Cannot create pre-compiled header: initialized data in header
In this example, the Dateutils.hpp is the file it's complaining about (CodeGear's header). I've seen this happen with other headers as well. What makes this interesting is that this only happens with some projects (same header being injected).
In the past, I've had to just find the header who ultimately included this errant file and remove it from my pre-compiled header file. Does anyone know what's going on here and the best way to fix it?
Update
I ended up performing a process of elimination approach to the header file and came up with an interesting finding that I cannot explain. Out of the 50+ headers that get included, when I removed vcl.h I no longer get the W8058 warnings. I do not understand this as I would imagine that this header file in particular is a prime candidate for pre-compiliation. Can anyone explain that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可能相关的一件事是 BCB 200x 处理默认字符串参数的方式。
像这样声明的函数会给出“无法生成预编译头”消息。
不过改成这样,就可以生成预编译头了。
One thing that may be related is the way default string parameters are handled by BCB 200x.
Functions declared like this give the "can't generate precompiled header" message.
However, change it to this, and the precompiled header can be generated.
根据我的经验,该警告消息具有误导性。 编译器似乎会识别标头可能已初始化数据的“候选者”,然后当它确定文件实际上没问题时,它就会继续。 如果没有找到其他候选者,则不会显示该消息。 如果它发现另一个候选者确实存在问题,则会显示有关第一个候选者的消息。
这使得识别真正的罪魁祸首变得极其困难。
In my experience, that warning message is misleading. It seems that the compiler identifies "candidates" where a header might have initialized data, then when it determines that the file is actually ok, it goes on. If it doesn't find another candidate, it won't show the message. If it finds another candidate that turns out to be a real problem, it then shows the message about the first candidate.
This makes identifying the real culprit extremely difficult.
有些 VCL 头文件存在此已知问题:QC 23002。 不过,该项目上标记的严重性是“小故障”。
因此,解决方法选项是有限的:
无论哪种方式,请确保 CodeGear 知道您遇到的那些头文件存在该问题。 这肯定是长期解决这个问题的最佳方法——让供应商解决他们的问题。 据说 CodeGear 在其内部测试中对此有 DateUtils.hpp,但已发布(对于 QC 2781),2007 年 7 月。如果问题或某些头文件对您影响很大,请与他们联系。
There are VCL header files that have this known issue: QC 23002. The marked severity on this item though is a "minor failure."
So the workaround options are limited:
Either way, make sure that of the ones you come across, CodeGear has knowledge of those header files having that issue. That will certainly be the best way to address it long term -- let the vendor fix their problem. Supposedly CodeGear has DateUtils.hpp in their internal tests for this, but that was posted (for QC 2781) in July 2007. If the problem or certain header files affect you considerably, contact them about it.
当代码显示时,我收到此警告消息:
我通过将这些行交换为以下内容找到了一个简单的修复:
警告不再出现。
I get this warning message when the code shows:
I found a simple fix by swapping these lines to:
Warning no longer appears.