今天编译android 报了个奇怪的error:
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
g++ -I external/zlib -I frameworks/base/libs/utils -I out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates -I dalvik/libnativehelper/include/nativehelper -I system/core/include -I hardware/libhardware/include
-I hardware/libhardware_legacy/include -I hardware/ril/include -I dalvik/libnativehelper/include -I frameworks/base/include -I frameworks/base/opengl/include -I frameworks/base/native/include -I external/skia/include -I tools/include -I out/host/linux-x86/obj/include
-c -fno-exceptions -Wno-multichar -m32 -fPIC -include system/core/include/arch/linux-x86/AndroidConfig.h -D_FORTIFY_SOURCE=0 -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -O2 -g -fno-strict-aliasing -DNDEBUG -UDEBUG -DANDROID
-fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Wsign-promo -DNDEBUG -UDEBUG -DLIBUTILS_NATIVE=1 -MD -o out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o frameworks/base/libs/utils/RefBase.cpp
<command-line>:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
<built-in>:0:0: note: this is the location of the previous definition
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]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1
百度了一下,才知道错误原因:
ubuntu 11.10的gcc版本是4.6.1,版本太高,编译android时出错,要把gcc版本改为4.4.3。
通过gcc -v命令可以发现gcc库在/usr/lib/gcc/i686-linux-gnu目录下,该目录下有当前系统支持的各种版本gcc库 。在安装gcc 4.4前该目录下是没有4.4目录的,安装gcc 4.4后该目录下就会多出4.4这个目录,且该4.4目录下有各种相应库文件。
ubuntu 32bit系统下安装gcc 4.4的最好方法是仅用以下两条命令,不需要其它命令,否则编译时可能会出错。
sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4
$ ls -l gcc*
lrwxrwxrwx 1 root root 7 2011-10-29 09:11 gcc -> gcc-4.6
-rwxr-xr-x 1 root root 224544 2011-10-06 05:47 gcc-4.4
-rwxr-xr-x 1 root root 302104 2011-09-17 05:43 gcc-4.6
sudo mv gcc gcc.bak
sudo ln -s gcc-4.4 gcc
ls -l g++*
lrwxrwxrwx 1 root root 7 2011-08-14 15:17 g++ -> g++-4.6
-rwxr-xr-x 1 root root 228640 2011-10-06 05:45 g++-4.4
-rwxr-xr-x 1 root root 306200 2011-09-17 05:39 g++-4.6
需要将g++链接改为g++-4.4:
/usr/bin$ sudo mv g++ g++.bak
/usr/bin$sudo ln -s g++-4.4 g++
然后继续编译,期间可能还发生g++ selected multilib '32' not installed的错误,需要:
sudo apt-get install g++-4.4-multilib