2.2. Installing on Windows

Getting the Glasgow Haskell Compiler(GHC) to run on Windows95/98 or Windows NT4 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. Your environment variables

Much of the Unixy stuff below involves setting environment variables. This section summarises how to set these variables on a Windows machine, in case you don't know alread.y On WinNT/Win2k, to edit your PATH variable (for example), do the following:

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 a Cygwin (see Section 2.2.3) shell 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 need to reboot to make the new settings take effect.

2.2.3. 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.3.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.

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.

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.

2.2.3.2. 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.4. 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.3); if that still doesn't help then please report the problems you're experiencing (see Chapter 7).

Further information on using GHC under Windows can be found in Sigbjørn Finne's pages.