首先做一下binutils
- [root@T-bagwell binutils-2.21]# ./configure --build=i686-pc-linux-gnu --target=arm-linux --prefix=/usr/local/arm/gcc-4.6.0/ --disable-nls --enable-shared --disable-multilib
- [root@T-bagwell binutils-2.21]# make configure-host
- [root@T-bagwell binutils-2.21]# make
- [root@T-bagwell binutils-2.21]# make install
- [root@T-bagwell binutils-2.21]# cp -vp include/libiberty.h /usr/local/arm/gcc-4.6.0/include
然后安装mpc,mpfr,gmp,要不会报错
- configure: error: Building GCC requires GMP 4.2 , MPFR 2.3.1 and MPC 0.8.0 .
- Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
- their locations. Source code for these libraries can be found at
- their respective hosting sites as well as at
- ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
- http://gcc.gnu.org/install/prerequisites.html for additional info. If
- you obtained GMP, MPFR and/or MPC from a vendor distribution package,
- make sure that you have installed both the libraries and the header
- files. They may be located in separate packages.
下载并安装gmp.mpfr,mpc就可以了
- [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
- [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
- [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
- [root@T-bagwell mnt]# tar zxvf mpc-0.8.1.tar.gz
- [root@T-bagwell mnt]# tar jxvf gmp-4.3.2.tar.bz2
- [root@T-bagwell mnt]# tar jxvf mpfr-2.4.2.tar.bz2
然后接着开始编译
- [root@T-bagwell mnt]# cd gmp-4.3.2
- [root@T-bagwell gmp-4.3.2]# ./configure --prefix=/usr/local/ --enable-shared
- [root@T-bagwell gmp-4.3.2]# make;make install
- [root@T-bagwell gmp-4.3.2]# cd ..;cd mpfr-2.4.2
- [root@T-bagwell mpfr-2.4.2]# ./configure --prefix=/usr/local/ --enable-shared --with-gmp=/usr/local/lib
- [root@T-bagwell mpfr-2.4.2]# make;make install
- [root@T-bagwell mpfr-2.4.2]# cd ..;cd mpc-0.8.1
- [root@T-bagwell mpc-0.8.1]# ./configure --prefix=/usr/local --with-gmp=/usr/local/lib --with-mpfr=/usr/local/lib
- [root@T-bagwell mpc-0.8.1]# make;make install
- [root@T-bagwell mpc-0.8.1]# cd ..
然后编译gcc
- [root@T-bagwell gcc-build]# AR=ar LDFLAGS="-Wl,-rpath,/usr/local/lib" ../gcc-4.6.0/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-linux --prefix=/usr/local/arm/gcc-4.6.0 --disable-shared --enable-static --enable-languages=c --without-headers --disable-threads --disable-multilib --disable-nls --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libssp --without-headers --with-newlib
- [root@T-bagwell gcc-build]# make all-gcc all-target-libgcc
- [root@T-bagwell gcc-build]# make install-gcc install-target-libgcc
这样,交叉编译器就做好了,看一下
- [root@T-bagwell gcc-build]# arm-linux-gcc -v
- Using built-in specs.
- COLLECT_GCC=arm-linux-gcc
- COLLECT_LTO_WRAPPER=/usr/local/arm/gcc-4.6.0/libexec/gcc/arm-linux/4.6.0/lto-wrapper
- Target: arm-linux
- Configured with: ../gcc-4.6.0/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-linux --prefix=/usr/local/arm/gcc-4.6.0 --disable-shared --enable-static --enable-languages=c --without-headers --disable-threads --disable-multilib --disable-nls --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libssp --without-headers --with-newlib
- Thread model: single
- gcc version 4.6.0 (GCC)
- [root@T-bagwell gcc-build]# ls /usr/local/arm/gcc-4.6.0/bin/
- addr2line arm-linux-c filt arm-linux-gcov arm-linux-objcopy arm-linux-strings event_rpcgen.py objcopy phar phpize strip
- ar arm-linux-cpp arm-linux-gprof arm-linux-objdump arm-linux-strip gprof objdump phar.phar ranlib
- arm-linux-addr2line arm-linux-elfedit arm-linux-ld arm-linux-ranlib as ld pear php readelf
- arm-linux-ar arm-linux-gcc arm-linux-ld.bfd arm-linux-readelf c filt ld.bfd peardev php-cgi size
- arm-linux-as arm-linux-gcc-4.6.0 arm-linux-nm arm-linux-size elfedit nm pecl php-config strings
- [root@T-bagwell gcc-build]#
可以交叉编译一下linuxkernel试试
- [root@T-bagwell gcc-build]# cd /media/mnt/linux-2.6/
- [root@T-bagwell linux-2.6]# git branch
- LiuQi
- master
- * s3c2440
- [root@T-bagwell linux-2.6]#
- [root@T-bagwell linux-2.6]# cp arch/arm/configs/mini2440_defconfig /media/mnt/linux-2.6/KERNEL_OBJ/.config
- [root@T-bagwell linux-2.6]# make ARCH=arm CROSS_COMPILE=arm-linux- O=/media/mnt/linux-2.6/KERNEL_OBJ zImage
编译完成以后,可以看一下编译出来以后的文件
- [root@T-bagwell linux-2.6]# file KERNEL_OBJ/arch/arm/boot/compressed/vmlinux
- KERNEL_OBJ/arch/arm/boot/compressed/vmlinux: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped
- [root@T-bagwell linux-2.6]#
搞定