如何生成许多标题的.pch? [英] How to generate .pch for lots of headers?

查看:373
本文介绍了如何生成许多标题的.pch?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码一直使用libcxx,sdl和一些其他libs。如何生成.pch考虑每个头可以包括一些其他头(即使有复杂的条件,如#ifdef #include #endif。这就是为什么很难理解需要的头文件列表。我应该只使用所有头文件

My code uses libcxx, sdl and some other libs all the time. How can I generate .pch taking into account every header can include some other headers (even with complex conditions like #ifdef #include #endif. That's why it's difficult to understand needed header files list. Should I just use just all header files found in that folders to create .pch? What about usage of such .pch performance in that case?

更新:如果有问题,我将使用它与Clang(不是
UPDATE2:

UPDATE: if it matters i'm going to use it with Clang (not GCC) and to be more specific via Clang C API. UPDATE2:

我已经为单个头文件创建了pch:

i've created pch for single header file:

MBA-Anton:pch asmirnov$ clang++ -x c++-header header.h -emit-pch -o header.pch
MBA-Anton:pch asmirnov$ clang++ -include-pch header.pch source.cpp -o source -x c++

但我无法为多个文件生成pch:

but i was unable to generate pch for multiple files:

MBA-Anton:pch asmirnov$ clang++ -x c++-header header.h header2.h -emit-pch -o headers.pch
clang: error: cannot specify -o when generating multiple output files


推荐答案

GCC 编译器仅适用于使用一个包含预编译标题如此答复中所述。因此,如果您想在GCC中使用PCH,则需要为应用程序的所有翻译单元都提供一个头文件(每个头文件应该以 #include 指令)

The GCC compiler works well only with one single included precompiled header, as explained in this answer. So if you want to use PCH in GCC, you'll need to have a single header file for all the translation units of your applications (and each of them should exactly start with that single #include directive)

我想这种情况对于支持某些预编译头文件的其他编译器也有帮助。 sup>

I guess that such a situation is also helpful for other compilers supporting some precompiled headers.

未来版本() C ++ 14 )可能定义了一个模块机制。参见例如 n4047 提案。

Future versions (post C++14) of the C++ standard might define a module mechanism. See e.g. n4047 proposal.

请注意,预编译的头是编译器特有的(使用GCC,当从GCC 4.9.1升级到GCC 4.9.2时,它们甚至可能不工作),所以你不应该依赖很多。

Notice that pre-compiled headers are very compiler specific (with GCC, they might not even work when ugrading from GCC 4.9.1 to GCC 4.9.2), so you should not depend too much on them.

这篇关于如何生成许多标题的.pch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆