序言:其实,如果没有充裕的时间,交叉编译器完全不用自己建,网上下载直接拿来用就可以了。
之所以写这博客,一是为了和大家交流,二是为了防止由于时间的流逝再也找不到当初的笔记。人说好记星不如烂笔头,但是对于我们这些飘在上海居无定所的人来说,好记性不如写博客,频繁的搬迁可以让你找不到当初的笔记本,但是博客还是存在的。
第一步:下载必要的文件,我下载的文件如下:
Binutils 2.20,
GCC version 4.4.3,
Glibc 2.9,
Glibc-ports 2.9,
GMP version 4.3.2,
MPFR version 3.0.1:
第二部:为了方便打开两个终端,分别命名为T1和T2
在TI下输入如下命令:
export BUILDDIR=/home/zdl/build
export SRCDIR=/home/zdl/sources
export TARGETMACH=arm-none-linux-gnueabi
export BUILDMACH=x86_64-pc-linux-gnu
export INSTALLDIR=/home/zdl/arm
export SYSROOTDIR=/home/zdl/arm/sysroot
在T2输入如下命令:export BUILDDIR=/home/zdl/build
export SRCDIR=/home/zdl/sources
export TARGETMACH=arm-none-linux-gnueabi
export BUILDMACH=x86_64-pc-linux-gnu
export INSTALLDIR=/home/zdl/arm
export SYSROOTDIR=/home/zdl/arm/sysroot
export CROSS=arm-none-linux-gnueabi
export CC=${CROSS}-gcc
export LD=${CROSS}-ld
export AS=${CROSS}-as
第三步:在/home/zdl下建立三个文件夹 sources,build,arm
以下是T1的行为:
将下载的文件解压到sources目录
编译binutils:
mkdir $BUILDDIR/binutils
../../sources/binutils-2.20/configure --build=$BUILDMACH
--prefix=$INSTALLDIR --with-sysroot=$SYSROOTDIR
--target=$TARGETMACH
make
make
install
安装内核头文件:
cd $SRCDIR/linux-2.6.18
make mrproper
make ARCH=arm s3c2410_defconfig
make ARCH=arm headers_checkmake ARCH=arm
INSTALL_HDR_PATH=$INSTALLDIR/sysroot/usr headers_install
Bootstrap
GCC:
mkdir
$BUILDDIR/init-gcc
cd $BUILDDIR/init-gcc../../sources/gcc-4.4.3/configure
--build=$BUILDMACH --host=$BUILDMACH --target=$TARGETMACH
--prefix=$INSTALLDIR --without-headers --enable-bootstrap
--enable-languages=c --disable-threads --enable-__cxa_atexit
--disable-libmudflap --with-gnu-ld --with-gnu-as --disable-libssp
--disable-libgomp --disable-nls --disable-shared
make all-gcc
install-gcc
make all-target-libgcc
install-target-libgcc
ln -s
/home/zdl/arm/lib/gcc/arm-none-linux-gnueabi/4.4.3/libgcc.a
/home/zdl/arm/lib/gcc/arm-none-linux-gnueabi/4.4.3/libgcc_sh.a
为glibc建立头文件:
mkdir
$BUILDDIR/libc-header
cd $BUILDDIR/libc-header
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
export PATH=$INSTALLDIR/bin:$PATH
../../sources/glibc-2.9/configure --build=$BUILDMACH
--host=$TARGETMACH --prefix=$SYSROOTDIR/usr
--with-headers=$SYSROOTDIR/usr/include --config-cache
--enable-add-ons=glibc-ports-2.9,nptl
--enable-kernel=2.6.18
libc_cv_c_cleanup=yes
make -k install-headers cross_compiling=yes
install_root=$SYSROOTDIR
ln -s /home/zdl/arm/lib/gcc/arm-none-linux-gnueabi/4.4.3/libgcc.a
/home/zdl/arm/lib/gcc/arm-none-linux-gnueabi/4.4.3/libgcc_eh.
建立glibc:
mkdir $BUILDDIR/glibc
cd $BUILDDIR/glibc
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
../../sources/glibc-2.9/configure \--build=$BUILDMACH
--host=$TARGETMACH --prefix=/usr
--with-headers=$SYSROOTDIR/usr/include --config-cache
--enable-add-ons=glibc-ports-2.9,nptl --enable-kernel=2.6.18
make -k install-headers cross_compiling=yes
install_root=$SYSROOTDIR
make
make install_root=$SYSROOTDIR install
为ARM建立GCC:
mkdir $BUILDDIR/gcc
cd $BUILDDIR/gcc
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
export CC=gcc
../../sources/gcc-4.4.3/configure --build=$BUILDMACH
--target=$TARGETMACH --prefix=$INSTALLDIR
--with-sysroot=$SYSROOTDIR --enable-languages=c --with-gnu-as
--with-gnu-ld --disable-multilib --with-float=soft \
--disable-sjlj-exceptions --disable-nls --enable-threads=posix
--enable-long-longx libc_cv_c_cleanup=yes
make all-gccmake
install-gcc
以下是T2的行为:
mkdir $BUILDDIR/gmp
cd $BUILDDIR/gmp
export CFLAGS=-static
../../sources/gmp-4.4.3/configure --build=$BUILDMACH
--host=$TARGETMACH --prefix=$INSTALLDIR --disable-shared
make
make install
mkdir $BUILDDIR/mpfr
cd $BUILDDIR/mpfr
../../sources/mpfr-3.0.1/configure --build=$BUILDMACH
--host=$TARGETMACH --prefix=$INSTALLDIR
--with-gmp=$INSTALLDIR
makemake install
建立最终的gcc:
mkdir $BUILDDIR/gcc-final
cd $BUILDDIR/gcc-final
export CC=gcc
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
../../sources/gcc-4.4.3/configure --build=$BUILDMACH
--target=$TARGETMACH --prefix=$INSTALLDIR
--with-sysroot=$SYSROOTDIR --enable-languages=c --with-gnu-ld
--with-gnu-as --disable-multilib --with-float=soft \
--disable-sjlj-exceptions --disable-nls --enable-threads=posix
--disable-libmudflap --disable-libssp \
--enable-long=longx --with-shared --with-gmp=$INSTALLDIR
--with-mpfr=$INSTALLDIR
makem
make install
下边就是测试了
sudo gedit
/etc/bash.bashrc
添加如下:
export
PATH=$INSTALLDIR/bin:$PATH 当然$INSTALLDIR要用实际的地址代替
注销后重新登录,在终端输入:
arm-none-linux-gnueabi-gcc
-v
显示其编译信息
在编译一个helloworld.c试一下,都通过。