2012年4月18日 星期三

Build Android Gingerbread with GCC 4.6

如果,將 Ubuntu 升級到 10.10 或更新的版本後,特別是將 GCC 升級為 4.6 以後的版本,那麼編譯 Android 2.3 的原始碼多半會遇到如下的錯誤訊息:

host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’:
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive]
host C++: libutils <= frameworks/base/libs/utils/ResourceTypes.cpp
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1
make: *** Waiting for unfinished jobs....
frameworks/base/libs/utils/ResourceTypes.cpp: In member function ‘void android::ResTable::print(bool) const’:
frameworks/base/libs/utils/ResourceTypes.cpp:4369:84: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
frameworks/base/libs/utils/ResourceTypes.cpp:4375:43: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

這是因 GCC 4.6 而引起的問題,修正方法如下:

diff -Naur old/frameworks/base/libs/utils/Android.mk new/frameworks/base/libs/utils/Android.mk
--- old/frameworks/base/libs/utils/Android.mk 2011-05-05 09:42:48.000000000 +0000
+++ new/frameworks/base/libs/utils/Android.mk 2012-04-07 15:45:40.738996228 +0000
@@ -57,7 +57,7 @@
 
 LOCAL_MODULE:= libutils
 
-LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
+LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive
 LOCAL_C_INCLUDES += external/zlib
 
 ifeq ($(HOST_OS),windows)

沒有留言:

張貼留言