2012年4月8日 星期日

Build Android Gingerbread with GCC 4.6

這兩天將 Debian 升級到 testing 版本後,沒想到編譯 Android 2.3 (Gingerbread) 時卻遇到了這樣的錯誤訊息:
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 版引起的,在用了下面這個 patch 後就搞定了:
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)
延伸閱讀:

沒有留言: