交叉编译工具可以通过以下方式获取:
1. 通过现有GNU tools 编译GNU tools源码来获取交叉编译工具。这种方法需要对GNU tools各个源码之间的版本匹配。
2.使用Dan Kegel开发的cross-tool脚本来编译源码。 该脚本是0.43版,本2006后没有新的版本出来。
3.在http://ftp.arm.linux.org.uk/pub/armlinux/toolchain/下载已经编译好的tools chains.
4.http://www.handhelds.org/download/projects/toolchain/ 下载已经编译好的tool chains.
5.http://www.denx.de/en/Software/WebHome 下载已经编译好的tool chains,他称之为ELDK.
//同时这家公司还是U-boot的开发者。
6. http://trac.cross-lfs.org 通过CLFS介绍的方法进行编译。
····································································································································
宿主机的安装和配置:
我用的是Fedora 10系统可从http://fedoraproject.org/zh_CN/get-fedora获得,其他系统没有进行试验。
·····································································································································
所需软件包:
<1>binutils-2.19.tar.bz2
<2>linux-2.6.33.tar.bz2
<3> GCC
gcc-4.4.3.tar.gz
gmp-4.3.1.tar.bz2
mpfr-2.4.1.tar.gz
<4>Glibc
glibc-2.9.tar.bz2
glibc-ports-2.9.tar.bz2
/*里面的版本和其他稍微有所不同,至于glibc的补丁我没有找到但经过实际测试,发现不打补丁也可正常编译通过*/
·····································································································································
编译步骤
step1: 创建目录和设定环境变量
mkdir -p /opt/package/cross-tools/source
mkdir -p /opt/package/cross-tools/build
mkdir -p /opt/cross-tools
export HOST=i686-pc-linux-gnu
export TARGET=arm-rui-linux-gnueabi
export PREFIX=/opt/cross-tools
////////////////////////////////////////////////////////////////////////////////////
step2:将下载的软件包放到source目录中
////////////////////////////////////////////////////////////////////////////////////
step3:编译binutils:
cd /opt/package/cross-tools/source
tar -jvxf binutils-2.19.tar.bz2
cd /opt/package/cross-tools/build
mkdir build-binutils
cd build-binutils
#../../source/ binutils-2.19/configure /
--target=$TARGET /
--prefix=$PREFIX /
--disable-nls /
--disable-werror /
--disable-multilib /
--enable-shared
make configure-host
make
make install
////////////////////////////////////////////////////////////////////////////////////
step4:制作linux内核头文件
cd /opt/package/cross-tools/source
tar -jvxf linux-2.6.33.tar.bz2
cd linux-2.6.33
make /
ARCH=arm /
CROSS_COMPILE=${TARGET}- /
INSTALL_HDR_PATH=${PREFIX}/${ TARGET} /
headers_install
/*指定ARCH=arm表示拷贝对应于ARM体系结构的头文件。虽然其中指定了 CROSS_COMPILE, 而此时交叉编译器还没有生成,这没有关系,因为根本不会用到交叉编译器*/
/////////////////////////////////////////////////////////////////////////////////////
step5: 编译静态gcc
cd /opt/package/cross-tools/source
tar -xzvf gcc-4.4.3.tar.gz
tar -jvxf gmp-4.3.1.tar.bz2
mv gmp-4.3.1 ./gcc-4.4.3/gmp
tar -xzvf mpfr-2.4.1.tar.gz
mv mpfr-2.4.1 ./gcc-4.4.3/mpfr
cd /opt/package/cross-tools/build
mkdir build-gcc
cd build-gcc
../../source/gcc-4.4.3/configure --target=$TARGET --prefix=$PREFIX --disable-shared --disable-threads --disable-nls --with-newlib --enable-languages=c --without-headers --with-sysroot=$PREFIX --disable-multilib --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libssp
make
make install
/*有时出错:checking for C compiler default output file name... configure: error: C compiler cannot create executables 可以尝试取消环境变量的设置
cat >> ~/.bashrc << EOF
unset CFLAGS
unset CXXFLAGS
EOF
其命令中已经将已经gmp-4.3.1.tar.bz2、mpfr-2.4.1.tar.gz解包并拷贝到了gcc的根目录下若没有这两个包gcc无法编译这是gcc4.3以后新引入的依赖*/
/////////////////////////////////////////////////////////////////////////////////////
step6:编译glibc
export PATH= $PREFIX /bin:$PATH
cd /opt/package/cross-tools/source
tar -jxvf glibc-2.9.tar.bz2
tar -jxvf glibc-ports-2.9.tar.bz2
mv glibc-ports-2.9 ./glibc-2.9/ports
cd /opt/package/cross-tools/build
mkdir build-glibc
cd build-glibc
为了使Glibc 支持NPTL ,需要在Glibc 编译目录下建立config.cache 文件并写入:
cat > config.cache << EOF
libc_cv_forced_unwind=yes
libc_cv_c_cleanup=yes
libc_cv_arm_tls=yes
libc_cv_gnu89_inline=yes
EOF
BUILD_CC=gcc CC=$TARGET-gcc AR=$TARGET-ar RANLIB=$TARGET-ranlib ../../source/glibc-2.9/configure --build=$HOST --host=$TARGET --target=$TARGET --prefix="/usr" --with-headers=$PREFIX/$TARGET/include --with-binutils=$PREFIX/bin --with-__thread --enable-sim --enable-nptl --disable-profile --enable-add-ons --with-tls --without-gd --without-cvs --cache-file=config.cache
make
make install_root=$PREFIX/$TARGET prefix="" install
对 libc.so 的修正·
vi $PREFIX /${TARGET}/lib/libc.so
去掉绝对路径,修改后的内容如下:
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux.so.3 ) )
//////////////////////////////////////////////////////////////////////////////////////////
step7 编译完整的gcc
cd /opt/package/cross-tools/build/build-gcc
rm -rf *
../../source/gcc-4.4.0/configure --build=$HOST --host=$HOST --target=$TARGET --prefix=$PREFIX --with-float=soft --enable-languages=c,c++ --enable-threads=posix --enable-c99 --enable-long-long --enable-shared --enable-__cxa_atexit --enable-nls --disable-libgomp
//这的选项可以与第一遍的时候相同。
make
make install
·····································································································································
注:一些编译选项的介绍参见其他文章。
参考文章:
http://blog.csdn.net/ruixj/archive/2009/05/30/4225886.aspx
http://cross-lfs.org/view/clfs-sysroot/arm/cross-tools/linux-headers.html
http://blog.csdn.net/chenzhixin/archive/2007/01/12/1481442.aspx