如何交叉編譯一個源碼包

如何交叉編譯一個源碼包

  1. 將交叉編譯工具鏈bin目錄添加到PATH

  2. ./configure 。 設置 --host=ppc-linux ( host 對應目標板架構及操作系統類型 )

可能會遇到 需要 修改 config.sub 的情況。對照arm 及 交叉編譯工具鏈的 gcc 前面的部分來添加即可。

如: 交叉編譯工具鏈叫做 ppc-linux-gcc 那麼 就應該添加 ppc-linux . 即交叉編譯鏈的 -gcc 前面的那部分。

321 | ppc-* | ppc-linux-* \

691 ppc*)
692 basic_machine=ppc-pc
693 os=-linux
694 ;;

其他的如 enable-xxx-xxx 根據實際情況 來進行配置。

  1. make

  2. make install


參考資料:

http://en.wikipedia.org/wiki/Cross_compile
http://www.airs.com/ian/configure/configure_5.html#SEC30
http://oss.lzu.edu.cn/blog/blog.php?/do_showone/tid_116.html
build 就是你現在使用的機器。
host 就是你編譯好的程序能夠運行的平臺。
target 編譯程序能夠處理的平臺。一般都用在構建編譯本身的時候(gcc), 才用target, 也就是說平時我們所說的交叉編譯用不到target.
The GNU autotools packages (i.e. autoconf, automake, and libtool) use the notion of a build platform, a host platform, and a target platform.
The build platform is where the code is actually compiled.
The host platform is where the compiled code will execute.
The target platform usually only applies to compilers. It represents what type of object code the package itself will produce (such as cross-compiling a cross-compiler); otherwise the target platform setting is irrelevant. For example, consider cross-compiling a video game that will run on a Dreamcast. The machine where the game is compiled is the build platform while the Dreamcast is the host platform.

When building cross compilation tools, there are two different systems involved: the system on which the tools will run, and the system for which the tools generate code.
The system on which the tools will run is called the host system.
The system for which the tools generate code is called the target system.
For example, suppose you have a compiler which runs on a GNU/Linux system and generates ELF programs for a MIPS embedded system. In this case the GNU/Linux system is the host, and the MIPS ELF system is the target. Such a compiler could be called a GNU/Linux cross MIPS ELF compiler, or, equivalently, a ‘i386-linux-gnu’ cross ‘mips-elf’ compiler.

Target usually have a meaning for developemt tool only.
比如: 在386的平臺上編譯可以運行在arm板的程序 ./configure –build=i386-linux,–host=arm-linux就可以了.
因爲一般我們都是編譯程序而不是編譯工具.
如果我們編譯工具,比如gcc,這個target就有用了.如果我們需要在一個我們的機器上爲arm開發板編譯一個可以處理 mips程序的gcc,那麼target就是mips了.

Example:
1. ./configure --build=mipsel-linux --host=mipsel-linux
–target=mipsel-linux’ will build native mipsel-linux binutils on
mipsel-linux.
2. ./configure --build=i386-linux --host=mipsel-linux
–target=mipsel-linux’ will cross-build native mipsel-linux binutils on
i386-linux.
3. ./configure --build=i386-linux --host=i386-linux
–target=mipsel-linux’ will build mipsel-linux cross-binutils on
i386-linux.
4. ./configure --build=mipsel-linux --host=i386-linux
–target=mipsel-linux’ will cross-build mipsel-linux cross-binutils for
i386-linux on mipsel-linux.

As you see, only if $build != $host a cross-compilation is performed.

原文:http://www.voidcn.com/article/p-gzrqtcly-bbn.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章