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 independent from cygwin1.dll, unlike the old one.
Update C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.sh :
#!/bin/bash export PATH=.:/usr/local/bin:/mingw/bin:/bin export PATH=$PATH:/c/WINDOWS/system32:/c/WINDOWS export PATH=$PATH:/c/WINDOWS/System32/Wbem export TARGET=i586-linux-gnu export PREFIX=/opt/crosstool/gcc-8.3.0-glibc-2.28/$TARGET cd /opt/crosstool/src/build-binutils find . -delete LDFLAGS="-Wl,-s -Wl,-static -static -static-libgcc" \ ../binutils-2.31.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 export PATH=$PATH:$PREFIX/bin cd /opt/crosstool/src/build-gcc find . -delete LDFLAGS="-Wl,-s -Wl,-static -static -static-libgcc" \ ../gcc-8.3.0/configure --target=$TARGET --prefix=$PREFIX \ --with-sysroot=$PREFIX --with-arch=i586 \ --disable-sjlj-exceptions --enable-checking=release \ --enable-linker-build-id --enable-gnu-unique-object \ --disable-nls --enable-languages=c,c++ \ --with-headers --enable-shared --enable-threads=posix \ --disable-multilib -enable-__cxa_atexit \ --disable-fixed-point \ --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 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 ==="
- Run C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
- If there are no errors, shutdown the MinGW VM and make snapshot "SNAP-D".
Notes:
- 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.
- LDFLAGS="-Wl,-s -Wl,-static -static -static-libgcc" option prevents dynamic linking to libgcc_s_dw2-1.dll (runtime library of MinGW) and also automatically strips EXE files at build time.
Additional steps to support 64-bit Linux target platform:
- Replace TARGET=i586-linux-gnu with TARGET=x86_64-linux-gnu and remove "--with-arch=i586" in build_gcc_cross.sh
- Run C:\MinGW\msys\1.0\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
- If there are no errors, shutdown the MinGW VM and make snapshot "SNAP-E".
>> Read next section or
buy already prepared
cross-compiler (€10) to save your time.