为什么交叉编译器有两个阶段的编译? [英] Why do cross-compilers have a two stage compilation?
问题描述
我目前正在尝试了解交叉编译器的工作方式。对于两阶段的编译器编译过程,我有些困惑。
I currently try to understand how cross-compilers work. I'm a bit confused about the two-staged compiler compilation process.
据我所读,应用了以下过程:
As far as I read, the following procedure is applied:
- 为目标体系结构编译 bintutils
- 编译 GCC (阶段1 )
- 使用GCC编译 newlib / eglibc /...
- 使用GCC编译 GCC libc (第2阶段)
- Compile bintutils for the target architecture
- Compile GCC (stage 1)
- Compile newlib/eglibc/... with GCC
- Compile GCC with the libc (stage 2)
为什么要涉及第二阶段?我不能只用 -lc
这样的标志调用第一级编译器来包含 libc 吗?
Why is there a second stage involved? Couldn't I just invoke the first stage compiler with some flag like -lc
to include libc?
推荐答案
我不确定为什么gcc具有如此复杂的构建过程。我基于clang / LLVM的ELLCC( http://ellcc.org )跨工具链项目的构建如下:
I'm not sure why gcc has such a complicated build process. My clang/LLVM based ELLCC (http://ellcc.org) cross tool chain project builds like this:
- 编译编译器(使用gcc或网站上提供的ELLCC编译器的预构建版本。)
- 使用编译器为所有目标构建C ++和C库。
- 为所有目标构建binutils和gdb(对于所有目标:请勿创建目标特定的实用工具, ld,gdb,objdump等都支持此功能)。
- (可选)使用新构建的编译器为所有目标交叉构建。
- Compile the compiler (using either gcc or a pre-built version of the ELLCC compiler available from the web site.).
- Use the compiler to build the C++ and C libraries for all targets.
- Build binutils and gdb for all targets (for all targets: don't make target specific utilitities except for the assemblers. ld, gdb, objdump, etc. all support this)
- (optional) Use your newly built compiler to cross build itself for all the targets.
BTW,ELLCC当前支持适用于Linux和裸机执行环境的ARM,Microblaze,Mips,PowerPC和x86目标。
BTW, ELLCC currently supports ARM, Microblaze, Mips, PowerPC, and x86 targets for Linux and bare metal execution environments.
这篇关于为什么交叉编译器有两个阶段的编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!