5.18. Cross GCC-4.6.0 - Final

The GCC package contains the GNU compiler collection, which includes the C and C++ compilers.

5.18.1. Installation of GCC Cross Compiler

The following patch contains a number of updates to the 4.6.0 branch by the GCC developers:

patch -Np1 -i ../gcc-4.6.0-branch_update-1.patch

Make a couple of essential adjustments to the specs file to ensure GCC uses our build environment:

patch -Np1 -i ../gcc-4.6.0-specs-1.patch

Change the StartFile Spec and Standard Include Dir so that GCC looks in /tools:

echo -en '#undef STANDARD_INCLUDE_DIR\n#define STANDARD_INCLUDE_DIR "/tools/include/"\n\n' >> gcc/config/rs6000/sysv4.h
echo -en '\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"\n' >> gcc/config/rs6000/sysv4.h
echo -en '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/rs6000/sysv4.h

Now alter gcc's c preprocessor's default include search path to use /tools only:

cp -v gcc/Makefile.in{,.orig}
sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" \
    gcc/Makefile.in.orig > gcc/Makefile.in

The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory:

mkdir -v ../gcc-build
cd ../gcc-build

Prepare GCC for compilation:

AR=ar LDFLAGS="-Wl,-rpath,/cross-tools/lib" \
  ../gcc-4.6.0/configure --prefix=/cross-tools \
  --build=${CLFS_HOST} --target=${CLFS_TARGET} --host=${CLFS_HOST} \
  --with-sysroot=${CLFS} --with-local-prefix=/tools --disable-nls \
  --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit \
  --with-mpfr=/cross-tools --with-gmp=/cross-tools --enable-c99 \
  --with-ppl=/cross-tools --with-cloog=/cross-tools \
  --enable-long-long --enable-threads=posix

The meaning of the new configure options:


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


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


Enable C99 support for C programs.


Enables long long support in the compiler.


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

Continue with compiling the package:


Install the package:

make install

Details on this package are located in Section 10.23.2, “Contents of GCC.”