摆脱预编译头文件
好的,我有适用于 Mac 和 Windows 的旧 Metrowerks 代码,其中之前的开发人员对该代码库构建的每个项目都使用了预编译标头。
从概念上讲,如何摆脱预编译头?
您是否将 .pch 的内容移至 core.h 并将其包含在所有类 .h 文件中?
我想转向使用 CMAKE 进行构建,尽管有一些技巧可以使预编译头正常工作,但我认为最好删除对它们的依赖关系。
有些人可能会说编译速度,但我不是在参加比赛,我已经有了快速的设备,我更感兴趣的是如何摆脱预编译头。
OK, I have old Metrowerks code for Mac and Windows where the previous developer used pre-compiled headers for every project that this code base builds.
How does one get rid of Pre-compiled headers, conceptually?
do you take the contents of a .pch and move them to a core.h and include that in all of your classes .h files?
I want to move to building with CMAKE and although there are hacks to make pre-compiled headers work, I think that it would be best to remove dependencies to them.
Some may say things about compile speed, but I am not in a race, I have fast equipment already, I am more interested in how to get away from pre-compiled headers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
预编译头是一种优化。从概念上讲,您只需使用常规标头即可摆脱预编译标头。
我认识这样做的程序员。就我个人而言,我更喜欢知道我正在使用哪些函数以及它们来自哪里,因此我确保每个文件
#include
包含编译该文件所需的所有标头(并且仅包含编译该文件所需的标头)文件)。话又说回来,这确实需要不断检查标头是否不再需要。Precompiled headers are an optimization. Conceptually you get rid of the precompiled headers by simply using the regular headers instead.
I know programmers who do this. Personally I prefer to know which functions I'm using and where they came from, so I make sure each file
#include
s all the headers needed to compile that file (and only the headers needed to compile that file). Then again, this does require constantly checking if a header is no longer necessary.在一个 C++ 项目中,绝对每个翻译单元都包含了一个中央头文件,反过来又包含了几乎所有的 Boost 头文件。在支持 PCH 的平台上效果很好,但我们正在一些不支持 PCH 的平台上进行编译,并且花费了很长时间。 (就像你的
core.h
方法一样。不要这样做,尤其是 C++。)所以,这里是:
是的,这就是暴力方法。不幸的是我不知道更好。
Been there... in a C++ project where a central header was included by absolutely every translation unit, and in turn included almost every Boost header there is. Nice on the platforms where PCH's are supported, but we're compiling on some where they aren't, and they took ages. (As would your
core.h
approach. Don't do that, especially not with C++.)So, here goes:
Yep, that's the brute force approach. Unfortunately I know no better.