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. 70M of disk space. The size of the installed GHC distribution is just(!) 17M, the rest is needed by supporting software.

To run GHC comfortably, your machine should have at least 32M 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 (beta20.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.

  • Download cygwin, beta20.1 (full.exe) from sourceware.cygnus.com Install this somewhere locally.

  • Create the following directories (if they aren't already there):

    • c:/etc

    • c:/bin

    • c:/usr/local/bin

    (using mkdir -p /bin, etc.)

  • Copy bash.exe from the bin directory of the cygwin tree (cygwin-b20/H-i586-cygwin32/bin/bash.exe) to /bin as sh.exe. You might think that it was easier to use bash directly from it original Cygwin directory, but (a) some UNIX utils have got /bin/sh hardwired in, and (b) the path following #! is limited to 32 characters.

  • 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:/cygnus/cygwin-b20/H-i586-cygwin32/bin. bash needs this, and when it is invoked from /bin it can't find it. c:/bin and c:/usr/local/bin should also be added.

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 werid 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.045—InstallShield installer, 10M: http or ftp

(The version number may change.) It is packaged up using an installer that should be familiar-looking to Windows users. Unpack and double click on setup.exe.

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 its job, you may delete the ghcInstall directory.

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.05/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: In case 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.

ghc-4.045 - gzip'ed tarfile, 7.5M: http or ftp

A `normal' GHC binary distribution packaged up as a compressed tar file. If you're already accustomed to installing and using GHC distributions on other platforms, the setup should be familiar to you, I hope. Unpack and read the INSTALL file contained in the distribution for instructions on how to set it up.

Notice that the top directory of the distribution contains (rather clumsily) a perl binary (version 5.005_02). If you haven't already got a working perl, install this somewhere along your path too.

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.05 -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.

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.07 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 H-i586-cygwin32/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.07 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.07 binaries and use those.