Building MINGW-w64
... for idiots. This guide is provided for those who have no clue how to compile gcc, but still want to do it. It's a reference, just follow the steps and you get what you want. There's no support for special wishes ;-)
Contents
Setting up the build environment
Download and install MSYS. You will need the following packages:
- msysCORE-1.0.14-1-msys-1.0.14-bin.tar.lzma
- coreutils-5.97-2-msys-1.0.11-bin.tar.lzma
- bash-3.1.17-2-msys-1.0.11-bin.tar.lzma
- bison-2.4.1-1-msys-1.0.11-bin.tar.lzma
- flex-2.5.35-1-msys-1.0.11-bin.tar.lzma
- gawk-3.1.7-1-msys-1.0.11-bin.tar.lzma
- grep-2.5.4-1-msys-1.0.11-bin.tar.lzma
- sed-4.2.1-1-msys-1.0.11-bin.tar.lzma
- make-3.81-2-msys-1.0.11-bin.tar.lzma
- m4-1.4.13-1-msys-1.0.11-bin.tar.lzma
- gcc-core-3.4.5-20060117-3.tar.gz
- gcc-g++-3.4.5-20060117-3.tar.gz
- binutils-2.20.1-2-mingw32-bin.tar.gz
- mingwrt-3.18-mingw32-dev.tar.gz
- w32api-3.14-mingw32-dev.tar.gz
- libregex-1.20090805-1-msys-1.0.11-dll-1.tar.lzma
- tar-1.22-1-msys-1.0.11-bin.tar.lzma
- diffutils-2.8.7.20071206cvs-2-msys-1.0.11-bin.tar.lzma
- gettext-0.17-1-msys-1.0.11-dev.tar.lzma
- libiconv-1.13.1-1-mingw32-dev.tar.lzma
Download all packages and extract them into c:\MSYS (or similar). You can unpack the .tar.lzma files using the latest version of 7zip.
Extract libiconv-1.13.1-1-mingw32-dev.tar.lzma into the mingw subfolder of the MSYS root (Why? Because!)
Getting the sources
Download all the sources into subfolders of /home/YourName/src
- binutils (version 2.20.51 or newer) -> home/YourName/src/binutils-2.20.51
- gcc-core (version 4.5.0 -> home/YourName/src/gcc-4.5.0
- gcc-g++ (version 4.5.0) -> home/YourName/src/gcc-4.5.0
- mingw-w64 [1] -> home/YourName/src/mingw-w64
- MPFR (version 2.4.2) -> home/YourName/src/mpfr
- GMP (version 5.0.1) -> home/YourName/src/gmp
- MPC (version 0.8.1) -> home/YourName/src/mpc
Note
If you wanna build a 64 bit GCC, just continue with the manual. If you need a 32 bit one, skip the patches below and use --host=i686-w64-mingw32 --build=i686-w64-mingw32 and --target=i686-w64-mingw32 with any configuration and not the ones mentioned otherwise.
Copy the src/mingw-w64/mingw-w64-headers/include directory to /RosBE64/mingw and to /RosBE64/x86_64-w64-mingw32 for 64 bit or /RosBE64/i686-w64-mingw32 for 32 bit.
Patching the sources
You need to apply 2 patches (Kudos go to Kai Tietz from mingw-w64):
Building
Optionally set buildflags:
export CFLAGS="-O2 -pipe -fomit-frame-pointer" export CXXFLAGS="-O2 -pipe -fomit-frame-pointer" export LDFLAGS=-s
Building GMP
Create a build subdirectory for gmp:
cd build mkdir gmp cd gmp
From the build directory run the gmp configure script:
../../src/gmp/configure --prefix=/RosBE64 --enable-cxx --host=i686-w64-mingw32 --build=i686-w64-mingw32 --disable-shared
Now build the whole stuff.
make
Finally install it into the designated directory.
make install
Building MPFR
Create a build subdirectory for mpfr:
cd build mkdir mpfr cd mpfr
From the build directory run the mpfr configure script:
../../src/mpfr/configure --prefix=/RosBE64 --with-gmp=/RosBE64 --host=i686-w64-mingw32 --build=i686-w64-mingw32 --disable-shared
Now build the whole stuff.
make
Finally install it into the designated directory.
make install
Building MPC
Create a build subdirectory for mpc:
cd build mkdir mpc cd mpc
From the build directory run the mpc configure script:
../../src/mpc/configure --prefix=/RosBE64 --with-gmp=/RosBE64 --with-mpfr=/RosBE64 --host=i686-w64-mingw32 --build=i686-w64-mingw32 --disable-shared
Now build the whole stuff.
make
Finally install it into the designated directory.
make install
Building binutils
Create a build subdirectory for binutils:
cd build mkdir binutils cd binutils
From the build directory run the binutils configure script:
../../src/binutils/configure --target=x86_64-w64-mingw32 --prefix=/RosBE64 --with-sysroot=/RosBE64 --disable-multilib --disable-nls
Now build the whole stuff.
make
Finally install it into the designated directory.
make install
Building gcc-core
Emter into the build directory:
cd .. mkdir gcc cd gcc
Now run the configure script:
../../src/gcc/configure --target=x86_64-w64-mingw32 --prefix=/RosBE64 --with-gmp=/RosBE64 --with-mpfr=/RosBE64 --with-mpc=/RosBE64 --with-sysroot=/RosBE64 --disable-multilib --disable-shared --disable-nls --with-pkgversion="RosBE64-Windows" --enable-languages=c,c++ --enable-checking=release --disable-win32-registry --enable-version-specific-runtime-libs
Compile the gcc-core
make all-gcc
And install it
make install-gcc
Finally add it to the PATH variable.
PATH=$PATH:/RosBE64/bin ; export PATH
Building the crt
Create a build directory.
cd .. mkdir mingw-w64-crt cd mingw-w64-crt
Run the configure script
../../src/mingw-w64/mingw-w64-crt/configure --host=x86_64-w64-mingw32 --prefix=/RosBE64 --with-sysroot=/RosBE64
Compile
make
And install
make install
Building the rest of gcc
Enter into the gcc build directory.
cd .. cd gcc
And compile the rest.
make make install
Common errors
When compiling crt:
configure: error: Please check if the mingw-w64 header set and the build/host option are set properly.
- Check if you have copied the mingw-headers/include directory to both /RosBE64/x86_64-w64-mingw32 and /RosBE64/mingw
- Check if you have set the PATH variable to the new compiler correctly
- Check if you have installed the new compiler correctly ("make install-gcc")
(--enable-leading-mingw64-underscores)