2.2. Installing on Windows

Getting the Glasgow Haskell Compiler (GHC) to run on Windows platforms can be a bit of a trying experience. This document tries to simplify the task by enumerating the steps you need to follow in order to set up and configure your machine to run GHC (at least that's the intention ;-)

2.2.1. System requirements

An installation of GHC requires ca. 200M of disk space, which is split roughly 50-50 between GHC and the supporting software. To run GHC comfortably, your machine should have at least 64M of memory.

2.2.2. Software required

You need two chunks of software other than GHC itself: the Cygwin toolchain, and Perl. Here's how to get and install them.

2.2.2.1. The cygwin toolchain (1.1)

GHC depends at the moment on the cygwin tools to operate, which dresses up the Win32 environment into something more UNIX-like. (notably, it provides gcc, as and ld), so you'll need to install these tools first. You also need Cygwin to use CVS. (We don't yet support later versions of Cygwin.)

Important grungy information about Cygwin:

  • Cygwin doesn't deal well with filenames that include spaces. "Program Files" and "Local files" are common gotchas.

  • Cygwin implements a symbolic link as a text file with some magical text in it. So programs that don't use Cygwin's I/O libraries won't recognise such files as symlinks. In particular, programs compiled by GHC are meant to be runnable without having Cygwin, so they don't use the Cygwin library, so they don't recognise symlinks.

Here's how to install Cygwin.

  • Install Cygwin 1.1 from sources.redhat.com Install this into your root directory (C:\), despite the warnings (but you may want to back up C:\bin, C:\etc, C:\lib, C:\usr and C:\var first) and choose DOS text mode. If you're upgrading from Cygwin B20.1, running mount --import-old-mounts immediately after installation may help. Either way, you want to end up with your main drive mounted in textmode, and only the bin directories mounted in binmode (you can check by running mount).

  • Create the following directories (if they aren't already there; substitute the drive you installed Cygwin on for c:):

    • c:/Temp

    • c:/etc

    • c:/bin

    • c:/usr/local/bin

    (using mkdir -p /bin, etc.)

  • If you're an Emacs user and want to be able to run bash from within a shell buffer, see the NT Emacs home page for instructions on how to set this up.

2.2.2.2. Environment variables

In case you don't already know how to set environment variables on a Windows machine, here's how. On WinNT/Win2k, to edit your PATH variable (for example), do the following:

  • Press Start/Settings/Control Panels

  • Double-click System

  • Press Advanced

  • Press Environment Variables

  • Under System Variables, select PATH

  • Press Edit

  • Add ";C:/whatever/" to the end of the string (for example)

  • Press OK

Some environment variables are “user variables” and some are “system variables”. I'm not sure of the difference but both are changed though the same dialogue.

In addition, when running bash you can set environment variables in your .bashrc file. But it is better to set your environment variables from the control panel (they get inherited by bash) because then they are visible to applications that aren't started by bash. For example, when you're invoking CVS (and ssh) via Emacs keybindings; it invokes cvs.exe without going via bash.

On a Win9x machine you need to edit autoexec.bat using Windows/system/Sysedit. You must reboot to make the new settings take effect.

The following environment variables must be set:

PATHSystem

Add c:/bin and c:/usr/local/bin. These should come before the Windows system directories (e.g. \WINNT\system32). You might want to set them in your .bashrc rather than in the system-wide PATH.

SHELLUser

c:/bin/sh.

HOMEUser

Set to point to your home directory. This is where, for example, bash will look for your .bashrc file.

MAKE_MODEUser

Set to UNIX. If you don't do this you get very weird messages when you type `make', such as:

/c: /c: No such file or directory
TMPDIRUser

Set to c:/tmp. For some reason, Win2k invisibly sets this variable to point to a temporary directory in your profile, that contains embedded spaces. If GHC sees the TMPDIR variable set, it tries to use it for temporary files, but Cygwin doesn't grok filenames with spaces, so disaster results.

Furthermore, it seems that TMPDIR must be set to a directory in the same file system in which you invoke GHC. Otherwise you get very weird messages when you invoke GHC, such as:
does not exist
Action: openFile
Reason: file does not exist /tmp/ghc11068.cpp
We think this is due to a bug in Cygwin.

In addition, we've had problems in the past with certain environment variables being set that seem to have bad effects on GHC. If you have installed other systems ported from Unix, you might too. If you get weird inexplicable failures to build GHC, then it might be worth weeding out unused environment variables. Known culprits from the past include GCC_EXEC_PREFIX and INCLUDE.

2.2.2.3. Perl5

The driver script is written in Perl, so you'll need to have this installed too. However, the ghc binary distribution includes a perl binary for you to make use of, should you not already have a cygwin compatible one. Note: GHC does not work with the ActiveState port of perl.

2.2.3. Installing GHC

Download a GHC distribution:

ghc-4.08—InstallShield installer, 15M: http

It is packaged up using an installer that should be familiar-looking to Windows users.

Note: The cygwin support for long file names containing spaces is not 100%, so make sure that you install ghc in a directory that has no embedded spaces (i.e., resist the temptation to put it in /Program Files/!)

When the installer has completed, make sure you add the location of the ghc bin/ directory to your path (i.e. /path/to/wherever/ghc-4.08/bin ). You need to do this in order to bring the various GHC DLLs into scope; if not, then you need to copy the DLLs into a directory that is (the system directory, for example).

Note: If you haven't got perl already installed, you will have to manually copy the perl.exe binary from the ghc bin/ into your /bin directory before continuing—the installer will not currently do this.

Make sure that you set all the environment variables described above under Cygwin installation, including TMPDIR

To test the fruits of your labour, try now to compile a simple Haskell program:

bash$ cat main.hs
module Main(main) where

main = putStrLn "Hello, world!"
bash$ /path/to/the/ghc/bin/directory/ghc-4.08 -o main main.hs
..
bash$ ./main
Hello, world!
bash$ 

OK, assuming that worked, you're all set. Go forth and write useful Haskell programs :-) If not, consult the installation FAQ (Section 2.2.4); if that still doesn't help then please report the problems you're experiencing (see Chapter 8).

Further information on using GHC under Windows can be found in Sigbjørn Finne's pages. Note: ignore the installation instructions, which are rather out of date; the Miscellaneous section at the bottom of the page is of most interest, covering topics beyond the scope of this manual.

2.2.4. Installing ghc-win32 FAQ

2.2.4.1. Invoking ghc doesn't seem to do anything, it immediately returns without having compiled the input file.
2.2.4.2. I'm having trouble with symlinks.
2.2.4.3. I'm getting ``permission denied'' messages from rm or mv.
2.2.4.4. I get errors when trying to build GHC 4.08 with GHC 4.05.

2.2.4.1. Invoking ghc doesn't seem to do anything, it immediately returns without having compiled the input file.

One cause of this is that /bin/sh is missing. To verify, open up a bash session and type ls -l /bin/sh.exe. If sh.exe is reported as not being there, copy bash.exe (which you'll find inside the cygwin installation tree as bin/bash.exe) to /bin/sh.exe.

All being well, ghc should then start to function.

2.2.4.2. I'm having trouble with symlinks.

Symlinks only work under Cygwin (Section 2.1.1.1), so binaries not linked to the Cygwin DLL, in particular those built for Mingwin, will not work with symlinks.

2.2.4.3. I'm getting ``permission denied'' messages from rm or mv.

This can have various causes: trying to rename a directory when an Explorer window is open on it tends to fail. Closing the window generally cures the problem, but sometimes its cause is more mysterious, and logging off and back on or rebooting may be the quickest cure.

2.2.4.4. I get errors when trying to build GHC 4.08 with GHC 4.05.

This seems to work better if you don't use -O in GhcHcOpts. It's a bug in 4.05, unfortunately. Anyway, better to install 4.08 binaries and use those.