构造arm-linux交叉编译工具链(Tool Chain)(转)
I donn’t know the real author of this article. If it’s pirate, I will remove it quickly
Linux kernel package used: (ftp://ftp.kernel.org/pub/linux/kernel/v2.6/)
linux-2.6.17.tar.gz
GNU compiler sources: (ftp://ftp.gnu.org/gnu/)
binutils-2.17.tar.gz
gcc-3.4.6.tar.gz
glibc-2.3.6.tar.gz
glibc-linuxthreads-2.3.6.tar.gz
Patches used: (http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/)
33_all_pr15068-fix.patch
5090_all_divdi3-asm-fix.patch
6200_all_arm-glibc-2.3.6-ioperm.patch
6230_all_arm-glibc-2.3.6-socket-no-weak-lias.patch
gcc_eh.patch.cross
1. Preparation
Create project directory like this:
/root/scholar
|
|–toolchain
| |–binutils-2.17.tar.gz
| |–gcc-3.4.6.tar.gz
| |–glibc-2.3.6.tar.gz
| |–glibc-linuxthreads-2.3.6.tar.gz
|
|–patches
| |–33_all_pr15068-fix.patch
| |–5090_all_divdi3-asm-fix.patch
| |–6200_all_arm-glibc-2.3.6-ioperm.patch
| |–6230_all_arm-glibc-2.3.6-socket-no-weak-lias.patch
| |–gcc_eh.patch.cross
|
|–kernel
|–linux-2.6.17.tar.gz
export PREFIX=/usr/local/arm/scholar
2. Building binutils-2.17
tar -zxvf binutils-2.17.tar.gz
cd binutils-2.17
mkdir arm-linux
cd arm-linux
../configure –target=arm-linux –prefix=$PREFIX –program-prefix=arm-linux-
make
make install
3. Bootstrap GCC (First time compiling GCC without glibc, only pure-C is supported)
tar -zxvf gcc-3.4.6.tar.gz
patch -p1 -d gcc-3.4.6 < patches/33_all_pr15068-fix.patch
cd gcc-3.4.6
vi gcc/config/arm/t-linux (TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer -fPIC -Dinhibit_libc -D__gthr_posix_h)
mkdir arm-linux
cd arm-linux
../configure –target=arm-linux –prefix=$PREFIX –program-prefix=arm-linux- –disable-threads –disable-shared –enable-languages=c
make
make install
4. Linux kernel header files (This step creates the arm-specified header files for glibc)
tar -zxvf linux-2.6.17.tar.gz
cd linux-2.6.17
make ARCH=arm CROSS_COMPILE=arm-linux- menuconfig
make include/linux/version.h
cp -dR include/linux $PREFIX/arm-linux/include/
cp -dR include/asm-generic $PREFIX/arm-linux/include/
cp -dR include/asm-arm $PREFIX/arm-linux/include/
mv $PREFIX/arm-linux/include/asm-arm $PREFIX/arm-linux/include/asm
5. glibc-2.3.6
tar -zxvf glibc-2.3.6.tar.gz
tar -zxvf glibc-linuxthreads-2.3.6.tar.gz –directory ./glibc-2.3.6
patch -p1 -d glibc-2.3.6 < patches/5090_all_divdi3-asm-fix.patch
patch -p1 -d glibc-2.3.6 < patches/6200_all_arm-glibc-2.3.6-ioperm.patch
patch -p1 -d glibc-2.3.6 < patches/6230_all_arm-glibc-2.3.6-socket-no-weak-lias.patch
patch -p1 -d glibc-2.3.6 < patches/gcc_eh.patch.cross
mkdir arm-linux
cd arm-linux
CC=arm-linux-gcc AR=arm-linux-ar RANLIB=arm-linux-ranlib LD=arm-linux-ld ../configure –target=arm-linux –prefix=$PREFIX/arm-linux –host=arm-linux –enable-add-ons=linuxthreads –enable-shared –with-headers=$PREFIX/arm-linux/include
make
make install
6. gcc-3.4.6 full version (with glibc, support C/C++)
cd gcc-3.4.6
Change ./gcc/config/arm/t-linux back to original
cd arm-linux
../configure –target=arm-linux –prefix=$PREFIX –program-prefix=arm-linux- –enable-multilib –with-headers=$PREFIX/arm-linux/include –enable-languages=c,c++
make
make install
自此,整个arm-linux的工具链也就生成了
Issue: I encounted one problem when I cross-compiled arm gcc, the log in the following
checking for arm-linux-gcc… /root/gcc-4.2.2/arm-linux/./gcc/xgcc -B/root/gcc-4.2.2/arm-linux/./gcc/ -B/arm-linux/bin/ -B/arm-linux/lib/ -isystem /arm-linux/include -isystem /arm-linux/sys-include
checking for C compiler default output file name… configure: error: C compiler cannot create executables
See `config.log’ for more details.
make[1]: *** [configure-target-libmudflap] Error 1
make[1]: Leaving directory `/root/gcc-4.2.2/arm-linux’
make: *** [all] Error 2
config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
configure:630: checking host system type
configure:651: checking target system type
configure:669: checking build system type
configure:724: checking for a BSD compatible install
configure:777: checking whether ln works
configure:801: checking whether ln -s works
configure:1866: checking for gcc
configure:1979: checking whether the C compiler (gcc ) works
configure:1995: gcc -o conftest conftest.c 1>&5
configure:2021: checking whether the C compiler (gcc ) is a cross-compiler
configure:2026: checking whether we are using GNU C
configure:2054: checking whether gcc accepts -g
configure:2121: checking for gnatbind
configure:2186: checking whether compiler driver understands Ada
configure:2218: checking how to compare bootstrapped objects
configure:2338: checking for correct version of gmp.h
configure:2351: gcc -c -g -O2 conftest.c 1>&5
configure:2364: checking for correct version of mpfr.h
configure:2378: gcc -c -g -O2 conftest.c 1>&5
configure:2368:18: error: mpfr.h: No such file or directory
configure:2371:36: error: missing binary operator before token “(”
configure: failed program was:
#line 2366 “configure”
#include “confdefs.h”
#include “gmp.h”
#include <mpfr.h>
int main() {
#if MPFR_VERSION < MPFR_VERSION_NUM(2,2,1)
choke me
#endif
; return 0; }
configure:2392: checking for any version of mpfr.h
configure:2402: gcc -o conftest -g -O2 conftest.c -lmpfr -lgmp 1>&5
configure:2396:18: error: mpfr.h: No such file or directory
configure: In function ‘main’:
configure:2398: error: ‘mpfr_t’ undeclared (first use in this function)
configure:2398: error: (Each undeclared identifier is reported only once
configure:2398: error: for each function it appears in.)
configure:2398: error: expected ‘;’ before ‘n’
configure:2398: error: ‘n’ undeclared (first use in this function)
configure: failed program was:
#line 2394 “configure”
#include “confdefs.h”
#include <gmp.h>
#include <mpfr.h>
int main() {
mpfr_t n; mpfr_init(n);
; return 0; }
configure:3513: checking for bison
configure:3513: checking for byacc
configure:3513: checking for yacc
configure:3553: checking for bison
configure:3592: checking for gm4
configure:3592: checking for gnum4
configure:3592: checking for m4
configure:3631: checking for flex
configure:3631: checking for lex
configure:3671: checking for flex
configure:3710: checking for makeinfo
configure:3763: checking for expect
configure:3804: checking for runtest
configure:3852: checking for i686-pc-linux-gnu-ar
configure:3927: checking for i686-pc-linux-gnu-as
configure:4002: checking for i686-pc-linux-gnu-dlltool
configure:4033: checking for dlltool
configure:4077: checking for i686-pc-linux-gnu-ld
configure:4152: checking for i686-pc-linux-gnu-lipo
configure:4183: checking for lipo
configure:4227: checking for i686-pc-linux-gnu-nm
configure:4302: checking for i686-pc-linux-gnu-ranlib
configure:4372: checking for i686-pc-linux-gnu-strip
configure:4442: checking for i686-pc-linux-gnu-windres
configure:4473: checking for windres
configure:4517: checking for i686-pc-linux-gnu-objcopy
configure:4592: checking for i686-pc-linux-gnu-objdump
configure:4704: checking for arm-linux-cc
configure:4704: checking for arm-linux-gcc
configure:4797: checking for arm-linux-c++
configure:4797: checking for arm-linux-g++
configure:4797: checking for arm-linux-cxx
configure:4797: checking for arm-linux-gxx
configure:4890: checking for arm-linux-gcc
configure:3852: checking for i686-pc-linux-gnu-ar
configure:3927: checking for i686-pc-linux-gnu-as
configure:4002: checking for i686-pc-linux-gnu-dlltool
configure:4033: checking for dlltool
configure:4077: checking for i686-pc-linux-gnu-ld
configure:4152: checking for i686-pc-linux-gnu-lipo
configure:4183: checking for lipo
configure:4227: checking for i686-pc-linux-gnu-nm
configure:4302: checking for i686-pc-linux-gnu-ranlib
configure:4372: checking for i686-pc-linux-gnu-strip
configure:4442: checking for i686-pc-linux-gnu-windres
configure:4473: checking for windres
configure:4517: checking for i686-pc-linux-gnu-objcopy
configure:4592: checking for i686-pc-linux-gnu-objdump
configure:4704: checking for arm-linux-cc
configure:4704: checking for arm-linux-gcc
configure:4797: checking for arm-linux-c++
configure:4797: checking for arm-linux-g++
configure:4797: checking for arm-linux-cxx
configure:4797: checking for arm-linux-gxx
configure:4890: checking for arm-linux-gcc
configure:4978: checking for arm-linux-gcj
configure:5071: checking for arm-linux-gfortran
configure:5539: checking for dlltool
configure:5593: checking for arm-linux-dlltool
configure:5849: checking for lipo
configure:5903: checking for arm-linux-lipo
configure:6624: checking for windres
configure:6678: checking for arm-linux-windres
configure:6759: checking where to find the target ar
configure:6792: checking where to find the target as
configure:6825: checking where to find the target cc
configure:6858: checking where to find the target c++
configure:6894: checking where to find the target c++ for libstdc++
configure:6930: checking where to find the target dlltool
configure:6963: checking where to find the target gcc
configure:6996: checking where to find the target gcj
configure:7032: checking where to find the target gfortran
configure:7068: checking where to find the target ld
configure:7101: checking where to find the target lipo
configure:7124: checking where to find the target nm
configure:7157: checking where to find the target objdump
configure:7190: checking where to find the target ranlib
configure:7223: checking where to find the target strip
configure:7256: checking where to find the target windres
configure:7317: checking whether to enable maintainer-specific portions of Makefiles
configure:7366: checking whether -fkeep-inline-functions is supported
configure:7381: gcc -c -g -O2 -fkeep-inline-functions conftest.c 1>&5