注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

itas109的博客

http://blog.csdn.net/itas109

 
 
 

日志

 
 

Issue 25412: NDK build tool : add support for precompiled header.  

2015-03-21 16:41:17|  分类: NDK |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

http://code.google.com/p/android/issues/detail?id=25412

 

Reported by olivier....@gmail.com, Feb 11, 2012

Hello,

The addition of ccache is very cool, but adding support for precompiled header within the Android.mk files would be perfect. Right now it take ages to compile if you are using a library like boost.

It would be very nice to declare something like this :

LOCAL_PRECOMPILED_HEADER = "..\PreComp\PreComp.h"

It would definitly save a lot of time.


Feb 13, 2012
Project Member #1 di...@android.com

absolutely a good idea.


Status: Assigned 
Owner: di...@android.com 
Feb 13, 2012
#2 olivier....@gmail.com

Nice !  Would be great to have a flag to avoid using the "pre-prend" on all c++ files, as some people are doing precompiled header the microsoft way ( including it in all files ) and some are doing it the "apple" or gcc way ( using the gcc flag to prepend an include files to all cpp file :)

Anyway thanks a lot ! sounds like a big time saver :)


Feb 13, 2012
Project Member #3 di...@android.com

(No comment was entered for this change.)


Cc: andrewhs...@google.com 
Apr 5, 2012
#4 daniel.z...@gamelion.blstream.com

Hi

Is there some progress in that feature?


May 15, 2012
#5 zhangxl...@gmail.com

I add a line as this:

LOCAL_PRECOMPILED_HEADER := "../../../source/Common/preHeader.h" in my Android.mk



but it seems not work at all.

Is there anyone really make it worked?


May 15, 2012
#6 Alex.Hol...@gmail.com

Attached patch for build-binary.mk which provides some basic PCH functionality for C++ only.  Usage:

LOCAL_PCH := src/stdafx.h

Generates stdafx.precompiled.h.gch in the obj directory, and passes -I obj -include stdafx.precompiled.h to g++ (this is necessary since GCC messes up relative paths on the PCH if it's just included from the source files directly).


Issue 25412:	NDK build tool : add support for precompiled header. - itas109 - itas109的博客 build-binary.mk.patch 
1.3 KB   View   Download

Oct 9, 2012
#7 ezradrei...@gmail.com

Patch from previous comment seems close but there are some problems with it:

1. I think there should be an "endif" at the end?

2. The line: LOCAL_CFLAGS += -Winvalid-pch -include $(LOCAL_BUILT_PCH)
should change LOCAL_CPPFLAGS instead so .c files will still compile ok.

and

3. I still could not get it to work because the header file gets compiled without the -mthumb it needs to be compatible with the other source files.  If I hand build the precompiled header instead with the -mthumb then the rest of it all works.

Tried but could not fix this last problem.  Adjusted patch attached.


Issue 25412:	NDK build tool : add support for precompiled header. - itas109 - itas109的博客 build-binary.mk.patch 
1.2 KB   View   Download

Oct 10, 2012
#9 apin...@gmail.com

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

change to this:

# 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)\
 )

This changes work for me. Now I can use *.pch file


Oct 31, 2012
#11 eanp...@gmail.com

I also had problem with -marm/-mthumb. I tried to fix this fast by calling "set-src-files-target-cflags" and had got compiled. NDK r8b

ifneq ($(TARGET_ARCH),x86) 
    $(call set-src-files-target-cflags,$(LOCAL_PCH),-mthumb)
endif

    # Build PCH 


Nov 1, 2012
#12 eanp...@gmail.com

But previous condition needs more complex if* like

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

because set-src-files-target-cflags remember previous settings (APP_ABI := armeabi armeabi-v7a x86)


May 8, 2013
#13 m...@danielsefton.com

The pathing in the patch doesn't work for me:

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

cc1plus: fatal error: src/Prefix.precompiled.h: No such file or directory
compilation terminated.

Why is it trying to find the *.precompiled.h in the source directory??


Sep 3, 2013
#14 krishna....@gmail.com

I followed the steps mentioned in this thread, but i do not see the .gch file getting created. Also, the compilation is taking same time as it was taking before without pre-compiled header. 

Please note that since we are passing the header by -include option, the code will compile fine but i think it is still not using he pre-compiled headers.


Mar 15, 2014
#15 Zhaojun....@gmail.com

Is there any plan to add precompiled header support?


May 3, 2014
#16 DodoEnte...@gmail.com

Hello all!

I tried all suggestions mentioned here and they did not work with NDK r9d. The patches submitted by Alex and  ezradrei were very close to my final solution. There were only missing toolchain specific compile flags.  Those flags are added by chosen toolchain based on "tags" attributed to each source file. Therefore, we needed to add appropriate tags to the PCH file and now everything works like a charm.

I've attached a patch to build-binary.mk which works with NDK r9d with armeabi and armeabi-v7a in both thumbs and arm mode.

Please try this patch yourself, test it also on mips and x86 and if it works good, please include it in next NDK release.


Issue 25412:	NDK build tool : add support for precompiled header. - itas109 - itas109的博客 build-binary.mk.patch 
2.5 KB   Download

Jun 24, 2014
Project Member #17 andrewhs...@google.com

Slightly modified patch submitted: https://android-review.googlesource.com/#/c/99193 Thanks for all contributions!


Status: FutureRelease 
Jul 17, 2014
Project Member #18 andrewhs...@google.com

(No comment was entered for this change.)


Status: Released 
Aug 17, 2014
#19 darkc...@gmail.com

This patch does not work when using Clang compilers. Changing the -include line to the following seems to fix it.

LOCAL_CPPFLAGS += -Winvalid-pch -include $(LOCAL_OBJS_DIR)/$(LOCAL_BUILT_PCH)


Nov 16, 2014
Project Member #20 andrewhs...@google.com

Thanks!  Fix on darkcube's behalf submitted:  https://android-review.googlesource.com/#/c/114840

Also see b.android.com/77575


Dec 15, 2014
#21 DodoEnte...@gmail.com

Hi everyone.

it appears that LOCAL_PCH does not work with absolute paths in Android studio and also does not respect tags.
I've attached a patch that solves the problem with absolute paths (apparently GCC cannot create PCH if output path is too long). Patch also makes sure that only files that are not tagged use PCH, while files with arm and neon tags ignore it.

Ideally, we would need specific PCH for each tag combination (something similar Xcode on ios does).


Issue 25412:	NDK build tool : add support for precompiled header. - itas109 - itas109的博客 build_binary.r10d.patch 
1.3 KB   Download

Feb 13, 2015
#22 fly...@gmail.com

same problem with #13

PCH_FILE := ../../Classes/stdafx.h
LOCAL_PCH := $(PCH_FILE)
LOCAL_CPPFLAGS += -DPCH

<command line>:9:10: fatal error: 
      './obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/stdafx.precompiled.h' file not found
#include "./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/stdafx.precompiled.h"
         ^
1 error generated.


-------------------
I found such code in build-binary.mk:
# Build PCH

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

from here we can see how stdafx.precompiled.h been used.
but didn't find any code to create stdafx.precompiled.h

So I copy my stdafx.h to the path that make need(just copy and change name to stdafx.precompiled.h):"./obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/stdafx.precompiled.h"

then it works.

I want know why? Did the mk file forget copy stdafx.h to stdafx.precompiled.h? Or I miss some steps to build the project


  评论这张
 
阅读(237)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017