x86_64 w64 mingw32 - Anonymous1157/cross-compilers GitHub Wiki

Cross-compiling to Windows with MinGW used to be a mess of patches to GNU toolchain components, but it can be built with upstream package versions nowadays. This toolchain uses mingw-w64 to target 64-bit Windows only, without multilib support, supporting as many languages as possible.

Install the header files for MinGW. These don't absolutely need to be available until later but we'll get them out of the way now.

mkdir mingw-headers
cd mingw-headers
../mingw-w64-v5.0.2/mingw-w64-headers/configure --prefix=$HOME/.local/share/cross/x86_64-w64-mingw32 --host=x86_64-w64-mingw32
make
make install
cd ..

Create a combined build tree. The order in which the trees are combined is important!

mkdir combined
cd combined
ln -sf path/to/gdb-7.12.1/* .
ln -sf path/to/binutils-2.28/* .
ln -sf path/to/gcc-6.3.0/* .
cd ..

Create a build directory and configure the toolchain.

mkdir combined-build
cd combined-build
../combined/configure \
	--prefix=$HOME/.local/share/cross \
	--target=x86_64-w64-mingw32 \
	--with-system-zlib \
	--with-system-readline \
	--with-gmp=$HOME/.local/share/cross \
	--with-mpc=$HOME/.local/share/cross \
	--with-mpfr=$HOME/.local/share/cross \
	--with-isl=SHOME/.local/share/cross \
	--enable-version-specific-runtime-libs \
	--disable-multilib \
	--enable-host-shared \
	--enable-shared \
	--with-{stage1,boot}-ldflags="-Wl,-rpath=$HOME/.local/share/cross/lib"
cd ..

Build and install just the host tools for the toolchain. The target libraries need MinGW to be available.

cd combined-build
make -j8 all-host
make install-host
cd ..

Build and install MinGW. Note that there's a bug in this release's build script that will completely recompile the CRT during make install! (The resulting install works fine.)

mkdir mingw
cd mingw
../mingw-w64-v5.0.2/configure \
	--prefix=$HOME/.local/share/cross/x86_64-w64-mingw32 \
	--host=x86_64-w64-mingw32 \
	--disable-lib32
make -j8
make -j8 install
cd ..

Build and install the target libraries for the toolchain.

cd combined-build
make -j8
make install
cd ..

That's it! You should have a working x86_64-w64-mingw32 toolchain now. Go cross-compile some Windows programs. PuTTY is a great test project to build and go run on a Windows machine if you want to test something straightforward.