export PREFIX=/cross/cross-arm cross gcc的bin会放到这个目录 export TARGET=arm-linux arm 上的linux
cd /cross/src 假设你下载的gcc 和binutil在这个目录(你当然要解压缩了) mkdir build-binutils build-gcc build-glibc
-------------------------------------------------------------------------------- 3) binutils (要分清host和target啊...) cd /cross/src/build-binutils ../binutils-x.xx/configure --target=$TARGET --prefix=$PREFIX --disable-nls make all make install
-------------------------------------------------------------------------------- 4) bootstrap gcc cd /cross/src/build-gcc export PATH=$PATH:$PREFIX/bin ../gcc-x.x.x/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c --without-headers --disable-shared --disable-threads --disable-libmudflap --disable-libssp make all-gcc make install-gcc
-without-headers :这个选项使你编译出的GCC不能使用标准库.(host cpu和target cpu一样的话,基本不用cross toolchain系统通过编译选项也能实现这个功能). --with-newlib 这只是个bug的work around,和newlib没有关系的. This
is only necessary if you are compiling GCC <= 3.3.x. That version
has a known bug that keeps --without-headers from working correctly.
Additionally setting --with-newlib is a workaround for that bug. --enable-languages :tell gcc需要哪些语言支持:font end, bootstrap gcc only surppot C tells GCC not to compile all the other language frontends it supports, but only C。 --disable-shared : 没有这个选项,会有 crti.o: No such file: No such file or directory collect2: ld returned 1 exit status --disable-thread : 没有这个选项的话会有, posix_thread.h can't not found 的问题 . --disable-libmudflap --disable-libssp :两个边界检查使用的库,有问题,禁止
NPTL problem fix: patch for glibc2.4: http://www.devfiles.jlime.com/parted/glibc/nptl-crosscompile.patch The following lines need to be added to config.cache for Glibc to support NPTL: echo "libc_cv_forced_unwind=yes" > config.cache echo "libc_cv_c_cleanup=yes" >> config.cache 最后使用参数--cache-file=config.cache 还不行,需要把asm-generic copy 到 $PREFIX/$TARGET/include .... (为啥经验这么重要呢。。)
$ tar -xvzf glibc-2.2.3.tar.gz $ tar -xzvf glibc-linuxthreads-2.2.3.tar.gz --directory=glibc-2.2.3
$ cd build-glibc $ CC=arm-linux-gcc ../glibc-2.2.3/configure --host=$TARGET --prefix=/usr --with-headers=$PREFIX/$TARGET/include --cache-file=config.cache