ubuntu12.04下用gcc4.6编译android4.0.3

许久没有编译了,用原来的方法编译,居然没有成功,特此记录。

原来是ubuntu12.04用gcc4.4编译,可以通过的,具体参照文章:

http://blog.csdn.net/flydream0/article/details/7046612

但是不知道为何这次没有成功。(注:后来才发现是只将gcc切换到了4.4,忘记切换g++了,汗~)


既然没有成功,就将gcc4.4仍然切换回gcc4.6,重新开始编译,过程如下:

1.搭建环境

参照:http://source.android.com/source/initializing.html

在上述链接指导下安装的环境(略过gcc,交叉编译器与jdk的安装)

$sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386

$sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so


2.开始编译,出现如下若干错误,解决如下:

编译错误解决
参考:
http://hcleon.iteye.com/blog/1461352
http://blog.csdn.net/jianchi88/article/details/7518697

============错误1===========================
host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
:0:0: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors

make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1

解决办法:
build/core/combo/HOST_linux-x86.mk line 61:
把:
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
改为:
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
参考:http://code.google.com/p/android/issues/detail?id=20795


============错误2=============================
(ir_dereference_variable*)’ [-Woverloaded-virtual]
external/mesa3d/src/glsl/linker.cpp: In function ‘void
assign_varying_locations(gl_shader_program*, gl_shader*, gl_shader*)’:
external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1394:50: error: ‘varyings’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1394:58: error: ‘offsetof’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1395:48: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:48: error: ‘position’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1414:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1414:48: error: ‘pointSize’ was
not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1424:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1424:48: error: ‘position’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1428:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1428:48: error:
‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1431:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1431:48: error:
‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp: In function ‘void
link_shaders(const gl_context*, gl_shader_program*)’:
external/mesa3d/src/glsl/linker.cpp:1734:49: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1734:50: error: ‘fragColor’ was
not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1734:59: error: ‘offsetof’ was not
declared in this scope
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/
libMesa_intermediates/src/glsl/linker.o] Error 1


解决方法:
把 "#include <stddef.h>" 添加到 linker.cpp 文件头部。


===========错误3==========================
In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:
external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1

解决办法:
external/oprofile/libpp/format_output.h
把:
mutable counts_t & counts;
改为:
counts_t & counts;


===========错误4===========================
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
解决办法:
vim external/gtest/src/../include/gtest/internal/gtest-param-util.h
添加#include <cstddef>
refer to:http://code.google.com/p/android/issues/detail?id=22005


===========错误5===========================
android_repo/external/llvm/lib/Support/Threading.cpp:96: undefined reference to `pthread_create'
android_repo/external/llvm/lib/Support/Threading.cpp:91: undefined reference to `pthread_attr_setstacksize'
android_repo/external/llvm/lib/Support/Threading.cpp:100: undefined reference to `pthread_join'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `MutexImpl':
android_repo/external/llvm/lib/Support/Mutex.cpp:69: undefined reference to `pthread_mutexattr_init'
android_repo/external/llvm/lib/Support/Mutex.cpp:75: undefined reference to `pthread_mutexattr_settype'
android_repo/external/llvm/lib/Support/Mutex.cpp:80: undefined reference to `pthread_mutexattr_setpshared'
android_repo/external/llvm/lib/Support/Mutex.cpp:89: undefined reference to `pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
android_repo/external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status

解决办法:
在external/llvm/llvm-host-build.mk
中添加
LOCAL_LDLIBS := -lpthread -ldl

refer to:http://code.google.com/p/android/issues/detail?id=22011


==================错误6====================================
host C++: libLLVMipo <= external/llvm/lib/Transforms/IPO/ExtractGV.cpp
frameworks/compile/slang/slang_rs_export_foreach.cpp: In static member function ‘static slang::RSExportForEach* slang::RSExportForEach::Create(slang::RSContext*, const clang::FunctionDecl*)’:
frameworks/compile/slang/slang_rs_export_foreach.cpp:249:23: error: variable ‘ParamName’ set but not used [-Werror=unused-but-set-variable]
host C++: libLLVMipo <= external/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
host C++: libLLVMipo <= external/llvm/lib/Transforms/IPO/GlobalDCE.cpp
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs_export_foreach.o] Error 1
make: *** Waiting for unfinished jobs....

解决办法:
vim frameworks/compile/slang/Android.mk
把:
local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter -Werror
改为:
local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter
参考:http://code.google.com/p/android/issues/detail?id=22006#c0
参考:http://groups.google.com/group/android-building/browse_thread/thread/0207abb98ed72304

—————————————————————————————————————————————————————————————————————————————

附上同事的解决方法,用gcc4.4成功编译:

在Ubuntu12。10下编译通过Android4.0.3,在

http://source.android.com/source/initializing.html的指导下安装的环境,可以编译Android4.2,

然后补安装以下库:
$sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib lib32ncurses5-dev

需要使用update-alternatives切换gcc/g++/cpp到4.4版本(以后可以切换回4.7),编译4.0.3无报错

注意:上述方法比http://blog.csdn.net/flydream0/article/details/7046612中要多装两个库:g++-4.4-multilib gcc-4.4-multilib


附录:
update-alternatives切换gcc用法:
In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As root:
apt-get install g++-4.5
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50
update-alternatives --set g++ /usr/bin/g++-4.5
update-alternatives --set gcc /usr/bin/gcc-4.5
update-alternatives --set cpp-bin /usr/bin/cpp-4.5

Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:
update-alternatives --auto g++
update-alternatives --auto gcc
update-alternatives --auto cpp-bin

(Note the use of cpp-bin instead of just cpp. Ubuntu already has a cpp alternative with a master link of /lib/cpp. Renaming that link would remove the /lib/cpp link, which could break scripts.)

To figure out the current priorities of gcc, type in the command:
update-alternatives --query gcc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值