ubuntu12.04LTS-ARM平台交叉编译器的制作

来源:互联网 发布:思途旅游cms 6.0 下载 编辑:程序博客网 时间:2024/06/08 09:22

原文链接:http://www.yyms.net/?p=530 所有步骤是LZ验证通过的,当然,因为运行环境的不同,可能中间会有些许区别,欢迎留言讨论。
对了,网站www.yyms.net是LZ的,所以文章并不是转载别人的。大笑

主机环境
    Ubuntu 12.04.2 LTS(cat /etc/lsb-release)
    gcc version 4.6.3
  1. Download source code
    1. binutils-2.22.tar.gz
    2. gcc-4.7.2.tar.bz2 
    3. gmp-5.0.5.tar.xz 
    4. mpfr-3.1.1.tar.xz 
    5. mpc-1.0.1.tar.gz 
    6. glibc-2.16.0.tar.xz 
    7. glibc-linuxthreads-2.5.tar.bz2 
    8. glibc-ports-2.16.0.tar.xz 
    9. linux-3.5.4.tar.bz2 
  2. 将以上源码放入arm-tool目录(或其它自建目录)
  3. 编译环境变量配置
    1. vim armenv,写入以下内容
      1. TARGET=arm-linux-gnueabi
      2. PREFIX=/opt/cross/gcc-4.7.2/$TARGET
      3. PATH=$PREFIX/bin:$PATH
      4. LD_LIBRARY_PATH=/opt/gmp-5.0.5/lib:/opt/mpfr-3.1.1/lib:/opt/mpc-1.0.1/lib
      5. export TARGET PREFIX PATH LD_LIBRARY_PATH
    2. source armenv使之生效
  4.  Instll binutils
    1. tar -xzf binutils-2.22.tar.gz 
    2. mkdir binutils-build 
    3. cd binutils-build 
    4. ../binutils-2.22/configure –target=$TARGET –prefix=$PREFIX 
    5. make -j2 
    6. make install
    7. cd .. 
  5. Install gmp安装在/opt/gmp-5.0.5下
    1. sudo mkdir -p /opt/gmp-5.0.5
    2. tar -jxvf gmp-5.0.5.tar.bz2
    3. cd gmp-5.0.5
    4. ./configure –prefix=/opt/gmp-5.0.5
    5. make && make check && sudo make install
  6. Install mpfr安装在/opt/mpfr-3.1.1
    1. mkdir -p /opt/mpfr-3.1.1
    2. tar -jxvf mpfr-3.1.1.tar.bz2
    3. cd  mpfr-3.1.1
    4. ./configure –prefix=/opt/ mpfr-3.1.1 –with-gmp=/opt/gmp-5.0.5
    5. make && make check && sudo make install
  7. Install mpc安装在/opt/mpc-1.0.1
    1. mkdir -p /opt/mpc-1.0.1
    2. tar -zxvf mpc-1.0.1 .tar.gz
    3. cd mpc-1.0.1
    4. ./configure –prefix=/opt/ mpc-1.0.1 –with-gmp=/opt/gmp-5.0.5  –with-mpfr=/opt/mpfr-3.1.1
    5. make && make check && sudo make install
  8. 第一次编译gcc
    1. mkdir gcc-bootstrap-build
    2. cd  gcc-bootstrap-build
    3. ../gcc-4.7.2/configure –target=$TARGET –host=x86-linux-gnu –build=x86-linux-gnu  –enable-targets=all –prefix=$PREFIX   –enable-languages=c –with-newlib –without-headers –disable-nls  –disable-threads –disable-shared –disable-libmudflap –disable-libssp  –disable-libgomp –disable-decimal-float –enable-checking=release  –disable-bootstrap –disable-libquadmath  –with-gmp=/opt/gmp-5.0.5 –with-mpfr=/opt/mpfr-3.1.1 –with-mpc=/opt/mpc-1.0.1
    4. make -j2 all-gcc
    5. make -j2 all-target-libgcc
    6. make install-gcc
    7. make install-target-gcc 
    8. cp -v libiberty/libiberty.a $PREFIX/lib 
    9. 以下两个添加 libgcc_eh.a,  ,libgcc_s.a到 libgcc.a的软链接
    10. ln -vs libgcc.a `arm-linux-gnueabi-gcc -print-libgcc-file-name | sed ‘s/libgcc/&_eh/’`
    11. ln -vs libgcc.a `arm-linux-gnueabi-gcc -print-libgcc-file-name | sed ‘s/libgcc/&_s/’` 
    12. cd ..
  9. 安装内核头文件
    1. tar -xjf linux-3.5.4.tar.bz2 
    2. cd linux-3.5.4 
    3. make ARCH=arm headers_check
    4. make ARCH=arm INSTALL_HDR_PATH=dest headers_install 
    5. mkdir /opt/cross/gcc-4.7.2/arm-linux-gnueabi/arm-linux-gnueabi/include
    6. sudo cp -rv dest/include/* $PREFIX/$TARGET/include 
    7. cd .. 
  10. 编译glibc库
    1. tar -xvf glibc-2.16.0.tar.xz
    2. tar -xvjf glibc-linuxthreads-2.5.tar.bz2 -C glibc-2.16.0  
    3. tar -xvf glibc-ports-2.16.0.tar.xz 
    4. mv glibc-ports-2.16.0 glibc-2.16.0/ports 
    5. mkdir glibc-build 
    6. cd glibc-build
    7. ../glibc-2.16.0/configure CC=$TARGET-gcc AR=$TARGET-ar RANLIB=$TARGET-ranlib –host=$TARGET –prefix=$PREFIX/$TARGET –with-tls –disable-profile –enable-add-ons –with-headers=$PREFIX/$TARGET/include libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes libc_cv_arm_tls=yes
    8. make -j2 
    9. make install 
    10. cd .. 
  11. 编译完整的gcc
    1. cd gcc-bootstrap-build
    2. ../gcc-4.7.2/configure –target=$TARGET –host=x86-linux-gnu –build=x86-linux-gnu –prefix=$PREFIX –enable-languages=c,c++ –enable-shared –with-gmp=/opt/gmp-5.0.5 –with-mpfr=/opt/mpfr-3.1.1 –with-mpc=/opt/mpc-1.0.1
    3. make -j2 
    4. make install 
    5. cd ..

Issue:

    configure: error: libmpfr not found or uses a different ABI (including static vs shared).
Solution:
    apt-get install libmpfr-dev
Issue:
    checking for suffix of object files… configure: error: in `/share/arm-tool/glibc-build’: 
    configure: error: cannot compute suffix of object files: cannot compile
Solution:
    export LD_LIBRARY_PATH=/opt/gmp-5.0.5/lib:/opt/mpfr-3.1.1/lib:/opt/mpc-1.0.1/lib
Issue:
    arm-linux-gnueabi/bin/ld: cannot find -lgcc
Solution:
    回到gcc编译目录执行以下命令
        make all-target-libgcc
        make install-target-libgcc
Issue:
    cannot find -lgcc_s
Solution:
    http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/glibc/2.16.0/
    下载0040_all_glibc-2.16-no-libgcc_s.patch文件打补丁
     patch -p1 -d glibc-2.16.0 < 0040_all_glibc-2.16-no-libgcc_s.patch
Issue:
    /opt/cross/gcc-4.7.2/arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/4.7.2/libgcc.a(libunwind.o): In function `_Unwind_Resume’:
    /share/arm-tool/gcc-bootstrap-build/arm-linux-gnueabi/libgcc/../../../gcc-4.7.2/libgcc/config/arm/libunwind.S:347: multiple definition of `_Unwind_Resume’
    /share/arm-tool/glibc-build/elf/static-stubs.o:/share/arm-tool/glibc-2.16.0/elf/static-stubs.c:32: first defined here
Solution:
    直接修改static-stubs.c,去除该函数定义
0 0
原创粉丝点击