Building Binutils & GCC in the MinGW VM
Now it's time to replace second 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_cross_toolchain.sh :
#!/bin/bash export PATH=.:/usr/local/bin:/bin:/c/MinGW/bin export PATH=$PATH:/c/WINDOWS/system32:/c/WINDOWS export PATH=$PATH:/c/WINDOWS/System32/Wbem export TARGET=arm-linux-gnueabihf export PREFIX=/opt/crosstool/gcc-4.9.2-glibc-2.19/$TARGET cd /opt/crosstool/src/build-binutils find . -delete ../binutils-2.25/configure --target=$TARGET \ --prefix=$PREFIX --with-sysroot=$TARGET \ --disable-nls --with-arch=armv6 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 ../gcc-4.9.2/configure --target=$TARGET --prefix=$PREFIX \ --with-arch=armv6 --with-fpu=vfp --with-float=hard \ --with-sysroot=$PREFIX \ --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 --with-mpfr --with-mpc 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 ==="
- Put C-style comments /* */ around "#define caddr_t char *" line in C:\MinGW\msys\1.0\opt\crosstool\src\gcc-4.9.2\gcc\configure
to prevent the following error during build:
In file included from ../../../gcc-4.9.2/libgcc/crtstuff.c:54:0: ../.././gcc/auto-host.h:1996:17: error: two or more data types in declaration specifiers #define caddr_t char * ^ In file included from ../../../gcc-4.9.2/libgcc/../gcc/tsystem.h:90:0, from ../../../gcc-4.9.2/libgcc/crtstuff.c:60: C:/MinGW/msys/1.0/opt/crosstool/gcc-4.9.2-glibc-2.19/arm-linux-gnueabihf/arm-linux-gnueabihf/include/sys/types.h:116:26: error: expected identifier or '(' before ';' token typedef __caddr_t caddr_t; ^ make[2]: *** [crtbegin.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
- Run C:\MinGW\msys\1.0\opt\crosstool\src\build_cross_toolchain.cmd and wait until it completes.
- If there are no errors, shutdown 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. It's useless on ARM.
- If you didn't specify --with-sysroot=$PREFIX configure option,
you will get the following error during build:Also you will get this error if you didn't merge $PREFIX/usr and $PREFIX/$TARGET folders during MinGW deployment phase (see previous page).
In file included from ../../../gcc-4.9.2/libgcc/../gcc/libgcc2.c:29:0:
../../../gcc-4.9.2/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
- If you didn't specify --disable-fixed-point configure option,
you will get the following errors during build:
C:\MinGW\msys\1.0\bin\make.exe: *** couldn't commit memory for cygwin heap, Win32 error 487 make[1]: *** [all-target-libgcc] Error 1 make[1]: Leaving directory `/opt/crosstool/src/build-gcc' make: *** [all] Error 2
andxgcc.exe: error: CreateProcess: No such file or directory make[2]: *** [libgcc_s.so] 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
First one is non-fatal (can be overcomed by re-running `make' command for a 3-4 times), second one is related to exceeding Win32 command line length limit and can't be trivially avoided.
Additional steps to support SoftFP ABI:
- Replace TARGET=arm-linux-gnueabihf with TARGET=arm-linux-gnueabi in build_cross_toolchain.sh
- binutils configure flags: --with-arch=armv4t
- gcc configure flags: --with-arch=armv4t --with-float=soft. Also remove --with-fpu=vfp.
- Run C:\MinGW\msys\1.0\opt\crosstool\src\build_cross_toolchain.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.