5.9. GCC-4.1.1 - Cross Compiler Final

#### Cross-Compiled Linux From Scratch - Version 1.0.0rc2-MIPS64-Pure64

### Chapter 5. Constructing Cross-Compile Tools

- Prev

  Glibc-2.4

- Next

  Building the Basic Tools

- Up.
- Home

# 5.9. GCC-4.1.1 - Cross Compiler Final

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

## 5.9.1. Installation of GCC Cross Compiler

The following patch fixes the searching of multilib dirs for specs file. The patch standardizes the gcc drivers path iteration functions, ensuring multilib directories are searched in the correct order. This fixes various issues, most noticably with libtool on multilib systems:

    patch -Np1 -i ../gcc-4.1.1-PR20425-1.patch

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

    patch -Np1 -i ../gcc-4.1.1-pure64_specs-1.patch

To make sure that a couple of tools use the proper syntax, apply the following patch:

    patch -Np1 -i ../gcc-4.1.1-posix-1.patch

The following patch ensures that gcc does not search the `/usr` directory for `libgcc_s.so` when cross-compiling:

    patch -Np1 -i ../gcc-4.1.1-cross_search_paths-1.patch

Change the StartFile Spec to point to the correct library location:

    echo "
    #undef STARTFILE_PREFIX_SPEC
    #define STARTFILE_PREFIX_SPEC \"/tools/lib/\"" >> gcc/config/linux.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

### Important

The above patches and sed's are critical in ensuring a successful overall build. Do not forget to apply them.

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:

    ../gcc-4.1.1/configure --prefix=/cross-tools \
        --target=${CLFS_TARGET} --host=${CLFS_HOST} --with-abi=64 \
        --with-local-prefix=/tools --disable-nls --enable-shared \
        --enable-languages=c,c++ --enable-__cxa_atexit --disable-multilib \
        --enable-c99 --enable-long-long --enable-threads=posix

The meaning of the new configure options:

`--with-abi=64`

  This option do ...

`--enable-languages=c,c++`

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

`--enable-__cxa_atexit`

  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`

  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.

Continue with compiling the package:

    make AS_FOR_TARGET="${CLFS_TARGET}-as" \
        LD_FOR_TARGET="${CLFS_TARGET}-ld"

Install the package:

    make install

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

- Prev

  Glibc-2.4

- Next

  Building the Basic Tools

- Up.
- Home.