如何使用precompiled标题中的Andr​​oid NDK的项目?如何使用、标题、项目、precompiled

由网友(浮生知星辰)分享简介:我从的Visual Studio A大C ++项目移植到 GCC 为Android。由于大量文件时,编译时间是冰川。我想设置一个precompiled头文件,但我发现 GCC文档混乱。I'm porting a big C++ project from Visual Studio to GCC for Androi...

我从的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
    

插入以下行到你的模块的android.mk:


    PCH_FILE := symroot/src/Prefix.h
    LOCAL_PCH := $(PCH_FILE)
    LOCAL_CPPFLAGS += -DPCH

所以,我们纪念我们的模块具有-DPCH compilator标志precompiled头(棘手,但工作的时候有很多的模块中的应用程序)。

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).

最的解决方案是从这里:http://$c$c.google.com/p/android/issues/detail?id=25412

The most of solution is taken from here: http://code.google.com/p/android/issues/detail?id=25412

警告:我已经与我的项目做到了这一点后,它并没有给我的人编译时间改进,我发现这种情况的发生与某些项目的gcc precompiled头。无法解释自己这个还没有。

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.

如果您只想包括一些文件到每个CPP文件,只需添加以下行的Andr​​oid.mk:

If you want just include some file into every cpp file, just add the following lines to android.mk:



    PCH_FILE := $(LOCAL_PATH)/symroot/src/Prefix.h
    LOCAL_CPPFLAGS += -include $(PCH_FILE) 

阅读全文

相关推荐

最新文章