Ubuntu 关于gcc/g++版本更换以及编译问题

前端之家收集整理的这篇文章主要介绍了Ubuntu 关于gcc/g++版本更换以及编译问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在编译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

else

LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32

endif

301 line,)

LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64

else

LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32

endif

641 line,

LOCAL_CFLAGS += (commonLOCALCFLAGS)I (intermediates) -m64

换成

ifneq($(BUILD_HOST_64bit),)

LOCAL_CFLAGS += (commonLOCALCFLAGS)I (intermediates) -m64

else

LOCAL_CFLAGS += (commonLOCALCFLAGS)I (intermediates) -m32

endif

730 line,)

LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m64

else

LOCAL_CFLAGS +=$(common_LOCAL_CFLAGS) -m32

endif

这是我的公众号:

猜你在找的Ubuntu相关文章