如何在Android NDK项目中使用预编译头?
我正在将一个大型 C++ 项目从 Visual Studio
移植到 Android 的 GCC
。由于文件数量巨大,编译时间非常缓慢。我想设置一个预编译头文件,但我找到了 GCC 文档 令人困惑。
我有 stdafx.h
文件,它应该是预编译头的基础,并且是所有 .cpp
源中的第一个包含文件。有谁知道我需要向 Android.mk
添加什么才能使其正常工作?
I'm porting a big C++ project from Visual Studio
to GCC
for Android. Because of the large number of files, the compile times are glacial. I would like to setup a precompiled header file, but I find the GCC documentation confusing.
I have the stdafx.h
file which should be the base of the precompiled headers and which is the first included file in all the .cpp
sources. Does anybody know what do I need to add to Android.mk
to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有同样的问题,所以有一个解决方案。首先,由于您似乎无法通过更改 android.mk 文件来做到这一点,因此您应该更改 ndk 构建系统中的文件,但这并不是很危险%)。该解决方案在 r8b NDK 上进行了测试。 :
# Build thesources to object files
之前:因此 我们将我们的模块标记为具有带有 -DPCH 编译器标志的预编译头(很棘手,但当应用程序中有很多模块时可以工作)。
大多数解决方案取自此处:http://code.google。 com/p/android/issues/detail?id=25412
警告:在我对我的项目完成此操作后,它根本没有给我带来编译时间的改进,我发现某些项目上的 gcc 预编译头会发生这种情况。还无法向自己解释这一点。
如果您只想在每个 cpp 文件中包含一些文件,只需将以下行添加到 android.mk 中:
Had the same problem, so there is a solution. First of all, as it seems to be you are not able to do it with changing the android.mk files, you should change file in the ndk built system, but this is not very dangerous %). This solution tested on r8b NDK. So:
# Build the sources to object files
:So we mark our module as having the precompiled header with -DPCH compilator flag (tricky, but work when there are a lot of modules in the application).
The most of solution is taken from here: http://code.google.com/p/android/issues/detail?id=25412
WARNING: after I have done this with my project, it did not give me compilation time improvement at all, and i found that this happens with gcc precompiled headers on some projects. Can't explain myself this yet.
If you want just include some file into every cpp file, just add the following lines to android.mk: