本帖最后由 AR9412 于 2016-8-13 22:01 编辑
大家好,本人新手,这次试着自己制作X86->ARM的交叉编译工具链,有一些问题想请教。
先说一下环境:
本机:x86_64-pc-linux-gnu
目标机:armv7l-unknown-linux-gnueabihf
本机是Archlinux系统,目标机运行ArchlinuxARM,都用的是glibc。
我参考了clfs 3.0的"Chapter 5. Constructing Cross-Compile Tools"这一章,下面是我制作交叉编译工具链的步骤:
先设置一下环境变量:
[mw_shl_code=shell,true]export PREFIX=/home/localdog/tmp/build_dir
export PATH=/home/localdog/tmp/build_dir/bin:$PATH[/mw_shl_code]
1.编译binutils:
[mw_shl_code=shell,true]AR=ar AS=as ../configure \
--prefix=$PREFIX --host=x86_64-pc-linux-gnu --target=armv7l-unknown-linux-gnueabihf --disable-nls \
--disable-static --disable-multilib --disable-werror
[/mw_shl_code]2.获得目标系统的内核头文件:
[mw_shl_code=shell,true]make mrproper
make ARCH=arm headers_check
make ARCH=arm INSTALL_HDR_PATH=$PREFIX headers_install
[/mw_shl_code]3.编译第一阶段的gcc:
[mw_shl_code=shell,true]AR=ar LDFLAGS="-Wl,-rpath,$PREFIX/lib" \
../configure --prefix=$PREFIX \
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=armv7l-unknown-linux-gnueabihf \
--with-native-system-header-dir=$PREFIX/include --disable-nls \
--disable-shared --without-headers --with-newlib --disable-decimal-float --disable-libgomp \
--disable-libmudflap --disable-libssp --disable-libatomic --disable-libitm \
--disable-libsanitizer --disable-libquadmath --disable-threads \
--disable-multilib --disable-target-zlib --with-system-zlib \
--enable-languages=c --enable-checking=release
[/mw_shl_code]4.编译目标系统的glibc:
[mw_shl_code=shell,true]BUILD_CC="gcc" CC="armv7l-unknown-linux-gnueabihf-gcc" \
AR="armv7l-unknown-linux-gnueabihf-ar" RANLIB="armv7l-unknown-linux-gnueabihf-ranlib" \
../configure --prefix=$PREFIX \
--host=armv7l-unknown-linux-gnueabihf --build=x86_64-pc-linux-gnu \
--disable-profile --enable-kernel=2.6.32 \
--with-binutils=$PREFIX/bin --with-headers=$PREFIX/include \
--enable-obsolete-rpc libc_cv_ssp=no
[/mw_shl_code]5.编译第二阶段的gcc:
[mw_shl_code=shell,true]AR=ar LDFLAGS="-Wl,-rpath,$PREFIX/lib" \
../configure --prefix=$PREFIX \
--build=x86_64-pc-linux-gnu --target=armv7l-unknown-linux-gnueabihf --host=x86_64-pc-linux-gnu \
--with-native-system-header-dir=$PREFIX/include --disable-nls \
--disable-static --enable-languages=c,c++ --enable-__cxa_atexit \
--disable-multilib \
--with-system-zlib \
--enable-checking=release --enable-libstdcxx-time
[/mw_shl_code]然后make:
[mw_shl_code=shell,true]make AS_FOR_TARGET="armv7l-unknown-linux-gnueabihf-as"\
LD_FOR_TARGET="armv7l-unknown-linux-gnueabihf-ld"
[/mw_shl_code]得到错误:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
对于编译通过的步骤我都没有写make的过程,我确认每一步都执行了make install
现在有几个问题是我不明白的:
1.编译第二阶段的gcc之前不需要make clean吗?clfs的book上没有写。
2.为何clfs的book上写第二阶段的gcc只需要
make AS_FOR_TARGET="armv7l-unknown-linux-gnueabihf-as"\
LD_FOR_TARGET="armv7l-unknown-linux-gnueabihf-ld",而不需要从头编译一次?
3.为何会出现找不到头文件的错误?我应该已经编译并安装好了目标系统的glibc了。
更新:如果第二阶段gcc的configure中加上--disable-threads的话会出现:
/home/localdog/tmp/build_dir/armv7l-unknown-linux-gnueabihf/bin/ld: cannot find crtn.o: No such file or directory
这个也是glibc的问题吧? |