如何使用precompiled标题中的Andr​​oid NDK的项目? [英] How to use precompiled headers in Android NDK project?

查看:408
本文介绍了如何使用precompiled标题中的Andr​​oid NDK的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从的Visual Studio A大C ++项目移植到 GCC 为Android。由于大量文件时,编译时间是冰川。我想设置一个precompiled头文件,但我发现 GCC文档混乱。

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.

我有的stdafx.h 文件,它应该是$ P $的基础pcompiled头和这是第一个包含文件中的所有的.cpp 来源。有谁知道该怎么做我需要添加到 Android.mk 来使这项工作?

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?

推荐答案

有同样的问题,所以有一个解决方案。首先,因为它似乎是你不能够与改变android.mk文件做到这一点,你应该改变的NDK内置的系统文件,但这不是很危险%)。该解决方案在R8B NDK进行测试。所以:

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:

  • 添加以下code到/build/core/build-binary.mk脚本,前#生成源对象文件


    #precompiled helper:
    ifeq ($(TARGET_ARCH_ABI),x86)
        $(call set-src-files-target-cflags,$(LOCAL_PCH),)
    else
        $(call set-src-files-target-cflags,$(LOCAL_PCH),-mthumb)
    endif

    # Build PCH
    #

    get-pch-name = $(strip \
        $(subst ../,__/,\
            $(eval __pch := $1)\
            $(eval __pch := $(__pch:%.h=%.precompiled.h))\
            $(__pch)\
        ))

    ifneq (,$(findstring DPCH,$(call module-get-c++-flags,$(LOCAL_MODULE))))
        # Build PCH into obj directory
        LOCAL_BUILT_PCH := $(call get-pch-name,$(LOCAL_PCH))

        $(call ndk_log, ___________________________Building pch '$(LOCAL_BUILT_PCH)'___________________________)

        # Build PCH
        $(call compile-cpp-source,$(LOCAL_PCH),$(LOCAL_BUILT_PCH).gch)

        # All obj files are dependent on the PCH
        $(foreach src,$(filter $(all_cpp_patterns),$(LOCAL_SRC_FILES)),\
            $($(LOCAL_OBJS_DIR)/$(call get-object-name,$(src)) : $(LOCAL_OBJS_DIR)/$(LOCAL_BUILT_PCH).gch)\
        )

        # Files from now on build with PCH
        LOCAL_CPPFLAGS += -Winvalid-pch -include $(LOCAL_BUILT_PCH)

        # Insert PCH dir at beginning of include search path
        LOCAL_C_INCLUDES := \
            $(LOCAL_OBJS_DIR) \
            $(LOCAL_C_INCLUDES)
    else
       $(call ndk_log, ___________________________NO PCH for this module___________________________)
    endif
    

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