原文链接: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
- Download source code
- binutils-2.22.tar.gz
- gcc-4.7.2.tar.bz2
- gmp-5.0.5.tar.xz
- mpfr-3.1.1.tar.xz
- mpc-1.0.1.tar.gz
- glibc-2.16.0.tar.xz
- glibc-linuxthreads-2.5.tar.bz2
- glibc-ports-2.16.0.tar.xz
- linux-3.5.4.tar.bz2
- 将以上源码放入arm-tool目录(或其它自建目录)
- 编译环境变量配置
- vim armenv,写入以下内容
- TARGET=arm-linux-gnueabi
- PREFIX=/opt/cross/gcc-4.7.2/$TARGET
- PATH=$PREFIX/bin:$PATH
- LD_LIBRARY_PATH=/opt/gmp-5.0.5/lib:/opt/mpfr-3.1.1/lib:/opt/mpc-1.0.1/lib
- export TARGET PREFIX PATH LD_LIBRARY_PATH
- source armenv使之生效
- vim armenv,写入以下内容
- Instll binutils
- tar -xzf binutils-2.22.tar.gz
- mkdir binutils-build
- cd binutils-build
- ../binutils-2.22/configure –target=$TARGET –prefix=$PREFIX
- make -j2
- make install
- cd ..
- Install gmp安装在/opt/gmp-5.0.5下
- sudo mkdir -p /opt/gmp-5.0.5
- tar -jxvf gmp-5.0.5.tar.bz2
- cd gmp-5.0.5
- ./configure –prefix=/opt/gmp-5.0.5
- make && make check && sudo make install
- Install mpfr安装在/opt/mpfr-3.1.1
- mkdir -p /opt/mpfr-3.1.1
- tar -jxvf mpfr-3.1.1.tar.bz2
- cd mpfr-3.1.1
- ./configure –prefix=/opt/ mpfr-3.1.1 –with-gmp=/opt/gmp-5.0.5
- make && make check && sudo make install
- Install mpc安装在/opt/mpc-1.0.1
- mkdir -p /opt/mpc-1.0.1
- tar -zxvf mpc-1.0.1 .tar.gz
- cd mpc-1.0.1
- ./configure –prefix=/opt/ mpc-1.0.1 –with-gmp=/opt/gmp-5.0.5 –with-mpfr=/opt/mpfr-3.1.1
- make && make check && sudo make install
- 第一次编译gcc
- mkdir gcc-bootstrap-build
- cd gcc-bootstrap-build
- ../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
- make -j2 all-gcc
- make -j2 all-target-libgcc
- make install-gcc
- make install-target-gcc
- cp -v libiberty/libiberty.a $PREFIX/lib
- 以下两个添加 libgcc_eh.a, ,libgcc_s.a到 libgcc.a的软链接
- ln -vs libgcc.a `arm-linux-gnueabi-gcc -print-libgcc-file-name | sed ‘s/libgcc/&_eh/’`
- ln -vs libgcc.a `arm-linux-gnueabi-gcc -print-libgcc-file-name | sed ‘s/libgcc/&_s/’`
- cd ..
- 安装内核头文件
- tar -xjf linux-3.5.4.tar.bz2
- cd linux-3.5.4
- make ARCH=arm headers_check
- make ARCH=arm INSTALL_HDR_PATH=dest headers_install
- mkdir /opt/cross/gcc-4.7.2/arm-linux-gnueabi/arm-linux-gnueabi/include
- sudo cp -rv dest/include/* $PREFIX/$TARGET/include
- cd ..
- 编译glibc库
- tar -xvf glibc-2.16.0.tar.xz
- tar -xvjf glibc-linuxthreads-2.5.tar.bz2 -C glibc-2.16.0
- tar -xvf glibc-ports-2.16.0.tar.xz
- mv glibc-ports-2.16.0 glibc-2.16.0/ports
- mkdir glibc-build
- cd glibc-build
- ../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
- make -j2
- make install
- cd ..
- 编译完整的gcc
- cd gcc-bootstrap-build
- ../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
- make -j2
- make install
- 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:
下载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,去除该函数定义