目录
1. 交叉编译 笔记
1.1. 交叉编译之 ./configure --build,--host,--target
设置
-
build: 执行代码编译的主机, 正常的话就是你的主机系统。这个参数一般由
config.guess
来猜就可以。当然自己指定也可以。 -
host: 编译出来的二进制程序所执行的主机, 因为绝大多数是本机编译, 本机执行, 所以这个值就等于 build。只有交叉编译的时候(也就是本机编译, 其他系统机器执行)才会 build 和 host 不同。用 host 指定运行主机。
-
target: 这个选项只有在建立交叉编译环境的时候用到, 正常编译和交叉编译都不会用到。他用 build 主机上的编译器, 编译一个新的编译器 (binutils, gcc, gdb 等), 这个新的编译器将来编译出来的其他程序将运行在 target 指定的系统上。
1.1.1. 让我们以编译 binutils 为例:
配置一:
./configure --build=mipsel-linux --host=mipsel-linux --target=mipsel-linux
说明: 我们利用 mipsel-linux 的编译器对 binutils 进行编译, 编译出来的 binutils 运行在 mipsel-linux, 这个 binutils 用来编译能够在 mipsel-linux 运行的代码。
作用: 当然没有人会用这个选项来编译 binutils
配置二:
./configure --build=i386-linux --host=mipsel-linux --target=mipsel-linux
说明: 利用 i386-linux 的编译器对 binutils 进行编译, 编译出来的 binutils 运行在 mipsel-linux, 这个 binutils 用来编译能够在 mipsel-linux 运行的代码。
作用: 这个选项可以用来为其他的机器编译它的编译器。
配置三:
./configure --build=i386-linux --host=i386-linux --target=mipsel-linux
说明: 我们利用 i386-linux 的编译器对 binutils 进行编译, 编译出来的 binutils 运行在 i386-linux, 这个 binutils 用来编译能够在 mipsel-linux 运行的代码。
作用: 这个选项用来在 i386 主机上建立一个 mipsel-linux 的交叉编译环境。
配置四:
./configure --build=mipsel-linux --host=i386-linux--target=mipsel-linux
说明: 我们利用 mipsel-linux 的编译器对 binutils 进行编译, 编译出来的 binutils 运行在 i386-linux, 这个 binutils 用来编译能够在 mipsel-linux 运行的代码。
作用: 这个选项可以用来在 i386 主机上建立一个 mipsel-linux 的交叉编译环境, 但是交叉编译环境在 mipsel-linux 编译出来, 安装到 i386-linux 主机上, 估计没有多少人会这么用吧。
总的来说, 只有 host != build
的时候编译才是交叉编译。否则就是正常编译。
1.1.2. 其他信息记录
操作一: 使用 gcc -v
查看配置信息
mayue6@Cpl-Ezviz-General-14-173:~/nfs/gdb$ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
目标: x86_64-linux-gnu
配置为: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
线程模型: posix
gcc 版本 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
操作二: 开源软件的交叉编译步骤
./configure –help 查看帮助文档
./configure –prefix=安装路径 --build=i686-linux-gnu --host=arm-poky-linux-gnueabi
make && make install
操作三: 当重新交叉编译时, 必须执行
make clean -w
make distclean