我在編譯android時,出現了以下問題:
ERROR: prebuilts/tools/gcc-sdk/../../gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/bin/x86_64-linux-ar only run on 64-bit linux
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libhost_intermediates/libhost.a] Error 1
解決方法:
看一下你的Ubuntu都裝了哪些版本的gcc 用命令:ls /usr/bin/gcc* -l 我的顯示是
lrwxrwxrwx 1 root root 7 2011-08-14 15:17 /usr/bin/gcc -> gcc-4.8
-rwxr-xr-x 1 root root 224544 2011-10-06 05:47 /usr/bin/gcc-4.8
-rwxr-xr-x 1 root root 237072 2011-09-17 17:25 /usr/bin/gcc-4.8
-rwxr-xr-x 1 root root 302104 2011-09-17 05:43 /usr/bin/gcc-4.6
由上面顯示可以看出默認安裝的是gcc-4.8,現在來改成gcc-4.6
刪除gcc-4.8的軟連接文件/usr/bin/gcc。(只是刪除軟連接)
命令:sudo rm /usr/bin/gcc
然後建一個軟連接,指向gcc-4.6。
命令:sudo ln -s /usr/bin/gcc-4.6 /usr/bin/gcc
ok了,www.linuxidc.com 現在用命令:gcc -v 顯示如下:
使用內建 specs。
目標:i686-linux-gnu
配置爲:../src/configure -v –with-pkgversion=’Ubuntu/Linaro 4.4.6-11ubuntu2’ –with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs –enable-languages=c,c++,fortran,objc,obj-c++ –prefix=/usr –program-suffix=-4.6 –enable-shared –enable-linker-build-id –with-system-zlib –libexecdir=/usr/lib –without-included-gettext –enable-threads=posix –with-gxx-include-dir=/usr/include/c++/4.6 –libdir=/usr/lib –enable-nls –with-sysroot=/ –enable-clocale=gnu –enable-libstdcxx-debug –enable-objc-gc –enable-targets=all –disable-werror –with-arch-32=i686 –with-tune=generic –enable-checking=release –build=i686-linux-gnu –host=i686-linux-gnu –target=i686-linux-gnu
線程模型:posix
gcc 版本 4.6.4 (Ubuntu/Linaro 4.6.4-11ubuntu2)
用同樣的方法更改g++的默認版本。
chunchun@****:/usr/bin$ ls -l g++*
lrwxrwxrwx 1 root root 7 6月 7 11:25 g++ -> g++-4.6
-rwxr-xr-x 1 root root 263328 4月 16 2012 g++-4.4
-rwxr-xr-x 1 root root 357312 4月 16 2012 g++-4.6
需要將g++鏈接改爲g++-4.4:
sudo mv g++ g++.bak
sudo ln -s g++-4.4 g++
修改後
chunchun@**:/usr/bin$ ls -l g++*
lrwxrwxrwx 1 root root 7 6月 7 11:25 g++ -> g++-4.4
-rwxr-xr-x 1 root root 263328 4月 16 2012 g++-4.4
-rwxr-xr-x 1 root root 357312 4月 16 2012 g++-4.6
lrwxrwxrwx 1 root root 7 3月 14 2012 g++.bak -> g++-4.6
再查看gcc和g++版本號:
gcc/g++更換成功,於是編譯android源碼,但結果下來
out/target/*****system.img後出現error,最後發現編譯沒有什麼問題,只是一些腳本文件還麼有成功.
/home/hsc/usr/Android/是我存放Android4.4的源代碼文件夾
根據錯誤提示: cd/home/hsc/usr/Android/prebuilts/tools/gcc-sdk/
然後把gcc文件下的第23到第39行註釋掉,除38行外。
操作:更改Android源代碼文件夾下的external/qemu/Makefile.target和Makefile.common文件
external/qemu/Makefile.target
252 line,
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
換成
ifneq($(BUILD_HOST_64bit),)
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
else
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32
endif
446 line,
LOCAL_LDLIBS +=$(common_LOCAL_LDLIBS) -m64
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
換成
ifneq($(BUILD_HOST_64bit),)
LOCAL_LDLIBS +=$(common_LOCAL_LDLIBS) -m64
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
else
LOCAL_LDLIBS +=$(common_LOCAL_LDLIBS) -m32
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32
endif
external/qemu/Makefile.common
149 line,
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
換成
ifneq($(BUILD_HOST_64bit),)
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
else
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32
endif
301 line,
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
換成
ifneq($(BUILD_HOST_64bit),)
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
else
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32
endif
641 line,
LOCAL_CFLAGS +=
換成
ifneq($(BUILD_HOST_64bit),)
LOCAL_CFLAGS +=
else
LOCAL_CFLAGS +=
endif
730 line,
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
換成
ifneq($(BUILD_HOST_64bit),)
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64
else
LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32
endif
這是我的公衆號: