Building Binutils & GCC in the MinGW VM

Now it's time to replace bootstrapping compiler with full-featured compiler tied to glibc and capable of building hosted code, not only freestanding code. Also new compiler will be indepenent from cygwin1.dll, unlike the old one.

  1. Update C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.sh :

    #!/bin/bash
    
    export TARGET=i486-linux-gnu
    export PREFIX=/opt/crosstool/gcc-4.4.1-glibc-2.10.1/$TARGET
    
    cd /opt/crosstool/src/build-binutils
    ../binutils-2.20.1/configure --target=$TARGET \
        --prefix=$PREFIX --with-sysroot=$TARGET \
        --disable-nls
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure binutils ==="
        exit 1
    fi
    make all
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make binutils ==="
        exit 1
    fi
    make install
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install binutils ==="
        exit 1
    fi
    
    cd /opt/crosstool/src/build-gcc
    export PATH=$PATH:$PREFIX/bin
    ../gcc-4.4.1/configure --target=$TARGET --prefix=$PREFIX \
         --with-sysroot=$PREFIX --with-arch=i486 --disable-nls \
         --enable-languages=c,c++ --with-headers \
         --enable-shared --enable-threads=posix \
         --disable-multilib --disable-libmudflap \
         --disable-libssp --disable-libgomp \
         --without-ppl --without-cloog \
         --with-gmp=/usr/local --with-mpfr=/usr/local \
         --with-mpc=/usr/local
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure gcc ==="
        exit 1
    fi
    make all
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make gcc ==="
        exit 1
    fi
    make install
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install gcc ==="
        exit 1
    fi
    
    echo "=== build script: OK ==="
    

  2. You may need to reapply dos2unix to build_gcc_cross.sh if your text editor does not preserve DOS/Unix line endings.
  3. Put C-style comments /* */ around "#define caddr_t char *" line in C:\MinGW\msys\1.0\opt\crosstool\src\gcc-4.4.1\gcc\configure to prevent caddr_t-related error in sys/types.h during GCC build.
  4. Run C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
  5. If there are no errors, shudown the MinGW VM and make snapshot "SNAP-D".

Notes:

  • There may be an error in $TARGET/usr/include/sys/types.h when building GCC (in the line "typedef __caddr_t caddr_t;"). Reason: you forgot to patch GCC configure script as described above.
  • Multilib is a special feature of GCC to allow building 32-bit targets on x86_64 platform. We don't use that one; we build two distinct cross-compilers instead.
  • "--with-mpc=/usr/local" should be omitted if you are using older GCC version which does not depend on mpc library.
  • If you didn't specify --with-sysroot=$PREFIX configure argument, you will get the following error during build:

    In file included from ../../../gcc-4.4.1/libgcc/../gcc/libgcc2.c:29:0:
    ../../../gcc-4.4.1/libgcc/../gcc/tsystem.h:87:19: fatal error: stdio.h: No such file or directory
    compilation terminated.
    make[2]: *** [_muldi3.o] Error 1
    make[2]: Leaving directory `/opt/crosstool/src/build-gcc/arm-linux-gnueabihf/libgcc'
    make[1]: *** [all-target-libgcc] Error 2
    make[1]: Leaving directory `/opt/crosstool/src/build-gcc'
    make: *** [all] Error 2
     

Additional steps to support 64-bit Linux target platform:

  1. Replace TARGET=i486-linux-gnu with TARGET=x86_64-linux-gnu and remove "--with=i486" in build_gcc_cross.sh
  2. You may need to reapply dos2unix to build_gcc_cross.sh if your text editor does not preserve DOS/Unix line endings.
  3. Run C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
  4. If there are no errors, shudown the MinGW VM and make snapshot "SNAP-E".


>> Read next section or buy already prepared cross-compiler ($10) to save your time.