食物垃圾处理器前景:[原创]自己动手制作交叉编译工具链(6)

来源:百度文库 编辑:九乡新闻网 时间:2024/07/07 15:42:40

第五步 编译GCC(第二次)

需要时间大概为:1小时

配置选项

这次是编译完整的GCC,因此第一次disable的一些选项这次可以enable了。

${SOURCE_DIR}/${PACKAGE_GCC}/configure \

   --build=${HOST} \

   --host=${HOST} \

   --target=${TARGET} \

   --prefix=${RESULT_DIR} \

   --with-float=soft \

   --with-cpu=arm920t \

   --with-tune=arm9tdmi \

   --enable-languages=c,c++ \

   --enable-threads=posix \

   --enable-c99 \

   --enable-long-long \

   --enable-shared \

   --enable-__cxa_atexit \

   --enable-nls \

   --disable-libgomp

make && make install

选项详解

-enable-languages=c,c++

This option ensures that only the C and C++ compilers are built.

--enable-__cxa_atexit

Thisoption allows use of __cxa_atexit, rather than atexit, to register C++destructors for local statics and global objects and is essential forfully standards-compliant handling of destructors. It also affects theC++ ABI and therefore results in C++ shared libraries and C++ programsthat are interoperable with other Linux distributions.

--enable-c99

Enable C99 support for C programs.

--enable-long-long

Enables long long support in the compiler.

--enable-threads=posix

This enables C++ exception handling for multi-threaded code.

--enable-nls \

--disable-libgomp

如果不加这一项会出现如下错误:

configure: error: Pthreads are required to build libgomp
make[1]: *** [configure-target-libgomp] 错误 1
make[1]:正在离开目录
`/home/hongwang/mktoolchain/build/gcc-4.4.0-2'
make: *** [all] 错误
2
没有找到好的解决办法,只能在configure里增加
--disable-libgomp

为什么要编译两次GCC

第一遍只编译一个支持c的gcc,原因是要编译出一个支持交叉的c++,必须有一个编译好的用于目标体系平台的glibc,而不是只有glibc的头文件就可以的,好在编译glibc有c支持就够了,所以编译glibc也成了第一遍的gcc唯一的理由和作用。工具链中gcc的第一次和第二次编译都是由主系统的gcc和binutils来完成的(之前没有提及binutils,只是为了理解方便,但实际上编译后是少不了链接过程的,这个过程是要binutils来完成的)。到目前为止只有在编译glibc的时候用到了交叉版本的binutils,其它部分的链接都是由主系统的binutils来完成的。