定制交叉编译环境-gcc

2019-03-05 09:55:52 浏览数 (1)

首先做一下binutils

  1. [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
  2. [root@T-bagwell binutils-2.21]# make configure-host
  3. [root@T-bagwell binutils-2.21]# make
  4. [root@T-bagwell binutils-2.21]# make install
  5. [root@T-bagwell binutils-2.21]# cp -vp include/libiberty.h /usr/local/arm/gcc-4.6.0/include

然后安装mpc,mpfr,gmp,要不会报错

  1. configure: error: Building GCC requires GMP 4.2 , MPFR 2.3.1 and MPC 0.8.0 .
  2. Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
  3. their locations. Source code for these libraries can be found at
  4. their respective hosting sites as well as at
  5. ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
  6. http://gcc.gnu.org/install/prerequisites.html for additional info. If
  7. you obtained GMP, MPFR and/or MPC from a vendor distribution package,
  8. make sure that you have installed both the libraries and the header
  9. files. They may be located in separate packages.

下载并安装gmp.mpfr,mpc就可以了

  1. [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
  2. [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
  3. [root@T-bagwell mnt]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
  4. [root@T-bagwell mnt]# tar zxvf mpc-0.8.1.tar.gz
  5. [root@T-bagwell mnt]# tar jxvf gmp-4.3.2.tar.bz2
  6. [root@T-bagwell mnt]# tar jxvf mpfr-2.4.2.tar.bz2

然后接着开始编译

  1. [root@T-bagwell mnt]# cd gmp-4.3.2
  2. [root@T-bagwell gmp-4.3.2]# ./configure --prefix=/usr/local/ --enable-shared
  3. [root@T-bagwell gmp-4.3.2]# make;make install
  4. [root@T-bagwell gmp-4.3.2]# cd ..;cd mpfr-2.4.2
  5. [root@T-bagwell mpfr-2.4.2]# ./configure --prefix=/usr/local/ --enable-shared --with-gmp=/usr/local/lib
  6. [root@T-bagwell mpfr-2.4.2]# make;make install
  7. [root@T-bagwell mpfr-2.4.2]# cd ..;cd mpc-0.8.1
  8. [root@T-bagwell mpc-0.8.1]# ./configure --prefix=/usr/local --with-gmp=/usr/local/lib --with-mpfr=/usr/local/lib
  9. [root@T-bagwell mpc-0.8.1]# make;make install
  10. [root@T-bagwell mpc-0.8.1]# cd ..

然后编译gcc

  1. [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
  2. [root@T-bagwell gcc-build]# make all-gcc all-target-libgcc
  3. [root@T-bagwell gcc-build]# make install-gcc install-target-libgcc

这样,交叉编译器就做好了,看一下

  1. [root@T-bagwell gcc-build]# arm-linux-gcc -v
  2. Using built-in specs.
  3. COLLECT_GCC=arm-linux-gcc
  4. COLLECT_LTO_WRAPPER=/usr/local/arm/gcc-4.6.0/libexec/gcc/arm-linux/4.6.0/lto-wrapper
  5. Target: arm-linux
  6. 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
  7. Thread model: single
  8. gcc version 4.6.0 (GCC)
  9. [root@T-bagwell gcc-build]# ls /usr/local/arm/gcc-4.6.0/bin/
  10. addr2line            arm-linux-c filt    arm-linux-gcov    arm-linux-objcopy  arm-linux-strings  event_rpcgen.py  objcopy  phar        phpize   strip
  11. ar                   arm-linux-cpp        arm-linux-gprof   arm-linux-objdump  arm-linux-strip    gprof            objdump  phar.phar   ranlib
  12. arm-linux-addr2line  arm-linux-elfedit    arm-linux-ld      arm-linux-ranlib   as                 ld               pear     php         readelf
  13. arm-linux-ar         arm-linux-gcc        arm-linux-ld.bfd  arm-linux-readelf  c filt            ld.bfd           peardev  php-cgi     size
  14. arm-linux-as         arm-linux-gcc-4.6.0  arm-linux-nm      arm-linux-size     elfedit            nm               pecl     php-config  strings
  15. [root@T-bagwell gcc-build]#

可以交叉编译一下linuxkernel试试

  1. [root@T-bagwell gcc-build]# cd /media/mnt/linux-2.6/
  2. [root@T-bagwell linux-2.6]# git branch
  3. LiuQi
  4. master
  5. * s3c2440
  6. [root@T-bagwell linux-2.6]#
  7. [root@T-bagwell linux-2.6]# cp arch/arm/configs/mini2440_defconfig /media/mnt/linux-2.6/KERNEL_OBJ/.config
  8. [root@T-bagwell linux-2.6]# make ARCH=arm CROSS_COMPILE=arm-linux- O=/media/mnt/linux-2.6/KERNEL_OBJ zImage

编译完成以后,可以看一下编译出来以后的文件

  1. [root@T-bagwell linux-2.6]# file KERNEL_OBJ/arch/arm/boot/compressed/vmlinux
  2. KERNEL_OBJ/arch/arm/boot/compressed/vmlinux: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped
  3. [root@T-bagwell linux-2.6]#

搞定

0 人点赞