Building GHC on Windows

This page documents the instructions for setting up a Windows build using MSYS2, which is a fairly complete build of MinGW-w64 + the MSYS2 tools.

This guide should get you running in ~5 minutes, modulo download speeds.

MSYS2 setup


Download and run the 64-bit MSYS2 installer. Be sure to open a mingw64 shell (see below).


Download and run the 32-bit MSYS2 installer. Be sure to open a mingw32 shell (see below).

The result of attempting to create a 32-bit build on a 64-bit machine has not been documented yet. Building on a 32-bit version of Windows works, of course.

From the MSYS2 installation instructions:

After installing or extracting MSYS2 you should start MSYS2 by executing msys2_shell.bat.

(if you did not use an installer and this is first time running of MSYS2 after unpacking, then at this point it will create the files and settings necessary for it to function properly. After this initial run you MUST restart MSYS2 so that the settings are correct)

Configuring MinGW properly

IMPORTANT: The MSYS2 installer creates multiple shortcuts, "MSYS2 Shell", "MinGW-w64 Win32 Shell" and "MinGW-w64 Win64 Shell". You do not want the "MSYS2 Shell." The MSYS2 shell is set up for building applications with Cygwin which provides an additional POSIX compatibility layer, while MinGW is set up for building native Windows applications which is what we need for GHC.

An easy way to check that you are running the right shell is to check the output of echo $MSYSTEM. It should show either MINGW32 or MINGW64. You can also tell by examining the $PATH.

*NOTE:* make sure /mingw64/bin (or /mingw32/bin depending on the arch you're building for) is the first thing on $PATH.

This is REQUIRED to ensure that the mingw-w64 variant of tools get priority over the msys versions. If using Bash then echo "export PATH=/mingw<bitness>/bin:\$PATH" >>~/.bash_profile can be run to append your profile. Replace <bitness> with either 64 or 32 depending on platform.

Upgrading MSYS2

The msys2 package uses pacman (the venerable ArchLinux package manager) to manage packages. Before installing system dependencies required for building GHC, you need to update packages according to MSYS2 installation instructions section III

With modern pacman (since version it's just pacman -Syuu.

If your pacman is somewhere between and

Run update-core. If one of the packages is updated during script run you MUST restart MSYS2

Run pacman -Su

For older versions refer to MSYS2 installation instructions

Installing packages & tools

Now we can install GHC's system dependencies as followed:

pacman -S --needed git tar binutils autoconf make \
    curl libtool automake python python2 p7zip patch \
    mingw-w64-$(uname -m)-gcc mingw-w64-$(uname -m)-python3-sphinx

If pacman fails with error message like this:

error: failed to commit transaction (conflicting files)
mingw-w64-x86_64-libiconv: /mingw64 exists in filesystem

then run the previous command with --force option. There is a bug witin MSYS2 installer (

Python and the test suite

There are two known issues when using python to run the GHC test suite:

  • The MinGW-w64 version of python (under the name mingw-w64-$(uname -m)-python) completely breaks on the GHC test suite (see #12554).
  • The MSYS2 version of python (which we recommended installing above using pacman -S python) is broken, but only with recent versions of the MSYS2 runtime (msys2-runtime >= 2.5.1). See #12661, as well as MSYS2-packages issue 707 for more info.

This issue manifests as a failure to remove directories; unfortunately this error is hidden by the driver and you will likely instead see an error of the form:

[Error 183] Cannot create a file when that file already exists: ...

from os.makedirs. This issue appears to happen more often when threading is enabled in the testsuite driver (e.g. make test THREADS=4 after disable the check disabling it in, but can also happen in single-threaded mode.

If you experience issues running the test suite on Windows, you can try the following:

  • Run pacman -Q msys2-runtime and verify that you are running a 2.5-series runtime.
  • If you are running a 2.5-series runtime, you can simply downgrade to the last-known-good version, 2.5.0, by running,
$ wget
$ pacman -U msys2-runtime-
  • After you have an MSYS2 installation with function runtime, you'll need to ensure that the testsuite driver runs with the MSYS2 python interpreter (located in /usr/bin/python), not the MinGW-w64 interpreter (located in /mingw*/bin/python). This can be accomplished with make test PYTHON=/usr/bin/python.

Unfortunately there's no easy way of doing this with ./validate. The easiest (but terrible) hack is adding this line:

$ alias python='/usr/bin/python'

to your ~/.bashrc file.

Host GHC setup

A host GHC binary is required for bootstrapping. In order to keep different architectures separate, download and install a prebuilt GHC into /mingw64 or /mingw32:

So for 64-bit you'd run

curl -L | tar -xJ -C /mingw64 --strip-components=1

and for 32-bit you'd run

curl -L | tar -xJ -C /mingw32 --strip-components=1

Note: --strip-components=1 places everything within the archive's ghc-7.10.1 folder directly into the target directory.

Cabal setup

Building GHC requires Alex and Happy. It is easiest to install them using cabal. We will also put them in /usr/local/bin, which is by default included in PATH in MSYS.

mkdir -p /usr/local/bin &&
curl -L | tar -xz -C /usr/local/bin &&
mv /usr/local/bin/cabal- /usr/local/bin/cabal.exe &&
cabal update &&
cabal install -j --prefix=/usr/local alex happy

Note for Windows Server 2008 R2 users

The pre-packaged cabal- crashes on Windows Server 2008 R2 during cabal update due to this bug. If so, try using a different version such as:

mkdir -p /usr/local/bin &&
pacman -S unzip &&
curl -LO &&
unzip -d /usr/local/bin &&
cabal update &&
cabal install -j --prefix=/usr/local alex happy

A Quick Build

You should now be able to build GHC:

# Clone to ./ghc
git clone --recursive git:// &&
cd ghc

Consider setting up mk/ here (cp mk/ mk/ && vim mk/

Finally, to perform the actual build:

./boot &&
./configure --enable-tarballs-autodownload &&

Running parallel make (e.g., make -j5) is faster, but appears to cause segfaults during the build sometimes. The reasons are not clear yet.

MSYS2 is known to be glitchy in some situations. If you see errors related to fork(), try closing and reopening the shell; see also msys2 issue #74. Also there have been issues with the build process segfaulting. The reason is not known (we're looking into it). If that happens, simply rerunning make will continue the build process.

Alternatively, to run a pristine build and tests (takes a while):


NOTE: You may see an error like make 7628 child_info_fork::abort: ... make: fork: Resource temporarily unavailable when running make. To fix this, go to the root of your MSYS dir and run autorebase.bat; see and again Alternatively, run shutdown //r.

NOTE: If the build seems super slow (takes more than 1 hour to complete), check your virus scanner and whitelist C:/msys64.

Other documentation

Other documentation for Windows includes:

Last modified 8 days ago Last modified on Oct 17, 2016 1:57:55 PM