# cross_compiler_creation **Repository Path**: jicanmeng/cross_compiler_creation ## Basic Information - **Project Name**: cross_compiler_creation - **Description**: 在pc上面如何创建一个交叉编译器 - **Primary Language**: Shell - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-31 - **Last Updated**: 2021-10-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README toolchain-i686.sh脚本来自于<<深度探索Linux操作系统>>工具链的命令, 在ubuntu12.10 32bit上面编译成功. toolchain-x86_64.sh在ubuntu12.10 64bit上面编译成功. toolchain-arm.sh和toolchain-powerpc.sh都在ubuntu12.10 64bit上面进行编译测试的, 都是在glibc阶段失败. 提示的错误也都是相同的, 都是cannot compile. log如下面所示: + mkdir glibc-build + cd glibc-build/ + ../glibc-2.15/configure --prefix=/usr --host=powerpc-none-linux-gnu --enable-kernel=3.7.4 --enable-add-ons --with-headers=/home/andy/work/linux_vita/sysroot/usr/include libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes libc_cv_ctors_header=yes configure: WARNING: if you wanted to set the --build type, don't use --host. If a cross compiler is detected then cross compile mode will be used checking build system type... x86_64-unknown-linux-gnu checking host system type... powerpc-none-linux-gnu checking for powerpc-none-linux-gnu-gcc... powerpc-none-linux-gnu-gcc checking for suffix of object files... configure: error: in `/home/andy/work/linux_vita/build/glibc-build': configure: error: cannot compute suffix of object files: cannot compile See `config.log' for more details andy@andy-VirtualBox:~/work/linux_vita/build$ 检查了glibc-build/config.log文件, 有如下提示: configure:2759: $? = 1 configure:2764: checking for suffix of object files configure:2786: powerpc-none-linux-gnu-gcc -c conftest.c >&5 as: unrecognized option '-mppc' configure:2790: $? = 1 自己写了一个a.c文件, 内容如下: int main() { return 0; } 执行如下命令: /vita/cross-gcc-tmp/bin/powerpc-none-linux-gnu-gcc -v -c a.c 输出结果如下: andy@andy-VirtualBox:/vita/build$ /vita/cross-gcc-tmp/bin/powerpc-none-linux-gnu-gcc -v -c a.c Using built-in specs. COLLECT_GCC=/vita/cross-gcc-tmp/bin/powerpc-none-linux-gnu-gcc Target: powerpc-none-linux-gnu Configured with: ../gcc-4.7.2/configure --prefix=/home/andy/work/linux_vita/cross-gcc-tmp --target=powerpc-none-linux-gnu --with-sysroot=/home/andy/work/linux_vita/sysroot --with-newlib --enable-languages=c --with-mpfr-include=/home/andy/work/linux_vita/build/gcc-4.7.2/mpfr/src --with-mpfr-lib=/home/andy/work/linux_vita/build/gcc-build/mpfr/src/.libs --disable-shared --disable-threads --disable-decimal-float --disable-libquadmath --disable-libmudflap --disable-libgomp --disable-nls --disable-libssp Thread model: single gcc version 4.7.2 (GCC) COLLECT_GCC_OPTIONS='-v' '-c' /home/andy/work/linux_vita/cross-gcc-tmp/libexec/gcc/powerpc-none-linux-gnu/4.7.2/cc1 -quiet -v -D__unix__ -D__gnu_linux__ -D__linux__ -Dunix -D__unix -Dlinux -D__linux -Asystem=linux -Asystem=unix -Asystem=posix a.c -quiet -dumpbase a.c -auxbase a -version -o /tmp/ccjxifHO.s GNU C (GCC) version 4.7.2 (powerpc-none-linux-gnu) compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/home/andy/work/linux_vita/sysroot/usr/local/include" ignoring nonexistent directory "/home/andy/work/linux_vita/cross-gcc-tmp/lib/gcc/powerpc-none-linux-gnu/4.7.2/../../../../powerpc-none-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /home/andy/work/linux_vita/cross-gcc-tmp/lib/gcc/powerpc-none-linux-gnu/4.7.2/include /home/andy/work/linux_vita/cross-gcc-tmp/lib/gcc/powerpc-none-linux-gnu/4.7.2/include-fixed /home/andy/work/linux_vita/sysroot/usr/include End of search list. GNU C (GCC) version 4.7.2 (powerpc-none-linux-gnu) compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 2e63017d2724559911ded76d6c3829d6 COLLECT_GCC_OPTIONS='-v' '-c' as -v -mppc -many -o a.o /tmp/ccjxifHO.s GNU assembler version 2.22.90 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.22.90.20120924 as: unrecognized option '-mppc' andy@andy-VirtualBox:/vita/build$ 两点需要注意: 1. -v选项会打印详细的调用过程 2. 可以看到, 调用了 /home/andy/work/linux_vita/cross-gcc-tmp/libexec/gcc/powerpc-none-linux-gnu/4.7.2/cc1 后, 后面调用的是pc机上的as程序, 而不是调用前面binutils编译出来的as程序. pc机器上面的as汇编器识别的是x86平台的汇编程序, 前面binutils编译出来的as汇编器识别的是powerpc平台的汇编程序. 而 /home/andy/work/linux_vita/cross-gcc-tmp/libexec/gcc/powerpc-none-linux-gnu/4.7.2/cc1 编译得到的汇编程序就是 powerpc平台的, 所以就有这个错误了. 我觉得是这个脚本的问题, 可能作者王柏生老师没注意到这个问题, 书上面虽然也是交叉编译, 但是编译的目标平台也是pc, 这个问题暴露不出来, 但涉及到其它的平台就会暴露了. 另外还有一点需要注意一下: 在glibc-2.15/README文件中指定了glibc支持的平台: The GNU C Library supports these configurations for using Linux kernels: i[34567]86-*-linux-gnu x86_64-*-linux-gnu powerpc-*-linux-gnu powerpc64-*-linux-gnu s390-*-linux-gnu s390x-*-linux-gnu ia64-*-linux-gnu sparc*-*-linux-gnu sparc64*-*-linux-gnu sh[34]-*-linux-gnu Requires Linux 2.6.11 The code for other CPU configurations supported by volunteers outside of the core glibc maintenance effort is contained in the separate `ports' add-on. You can find glibc-ports-VERSION distributed separately in the same place where you got the main glibc distribution files. Currently these configurations are known to work using the `ports' add-on: alpha*-*-linux-gnu Requires Linux 2.6.9 for NPTL arm-*-linux-gnu Requires Linux 2.6.15 for NPTL, no SMP support arm-*-linux-gnueabi Requires Linux 2.6.16-rc1 for NPTL, no SMP mips-*-linux-gnu Requires Linux 2.6.12 for NPTL mips64-*-linux-gnu Requires Linux 2.6.12 for NPTL 所以, 对于目标平台, 可以是i686-*-linux-gnu, 也可以是powerpc-*-linux-gnu. 不过, 如果目标平台是arm-none-linux-gnu, 那就需要额外再下载一个ports插件. 对于glibc-2.15版本有这个限制,最新的版本中就不需要额外下载ports插件了.