摆脱预编译头文件

发布于 2024-08-10 19:05:49 字数 272 浏览 4 评论 0原文

好的,我有适用于 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 技术交流群。

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

发布评论

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

评论(2

身边 2024-08-17 19:05:49

从概念上讲,如何摆脱预编译头?

预编译头是一种优化。从概念上讲,您只需使用常规标头即可摆脱预编译标头。

您是否将 .pch 的内容移至 core.h 并将其包含在所有类 .h 文件中?

我认识这样做的程序员。就我个人而言,我更喜欢知道我正在使用哪些函数以及它们来自哪里,因此我确保每个文件 #include 包含编译该文件所需的所有标头(并且仅包含编译该文件所需的标头)文件)。话又说回来,这确实需要不断检查标头是否不再需要。

How does one get rid of Pre-compiled headers, conceptually?

Precompiled headers are an optimization. Conceptually you get rid of the precompiled headers by simply using the regular headers instead.

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

东风软 2024-08-17 19:05:49

在一个 C++ 项目中,绝对每个翻译单元都包含了一个中央头文件,反过来又包含了几乎所有的 Boost 头文件。在支持 PCH 的平台上效果很好,但我们正在一些不支持 PCH 的平台上进行编译,并且花费了很长时间。 (就像你的 core.h 方法一样。不要这样做,尤其是 C++。)

所以,这里是:

  • grep 查找 PCH 的所有包含内容,然后扔掉它们(或者,更温和地) ,将其注释掉)。
  • 对于每个翻译单元,尝试构建并添加缺失的包含,直到不再出现编译器错误。

是的,这就是暴力方法。不幸的是我不知道更好。

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:

  • grep for all inclusions of the PCH, and toss 'em (or, more gently, comment them out).
  • for each translation unit, try to build, and add missing includes until you no longer get compiler errors.

Yep, that's the brute force approach. Unfortunately I know no better.

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