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.
An installation of GHC requires about 50M of disk space (which can be lowered by choosing a “compact” installation). The Cygwin support tools take another 200M or so (though if you really need to this can be halved by installing only the following packages: bash, binutils, cygwin, diff, fileutils, findutils, gcc, grep, make, perl, mingw, sed, textutils, w32api; however, it's fiddly and not recommended, and if you're trying to build rather than just use GHC, you need many more, so you might as well install the lot). To run GHC comfortably, your machine should have at least 64M of memory.
You need two chunks of software other than GHC itself: the Cygwin toolchain, and Perl. Here's how to get and install them.
At the moment you'll need Cygwin to use GHC. Cygwin dresses up the Win32 environment into something more UNIX-like; (notably, it provides gcc, as and ld). 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.
Install the latest Cygwin 1.1.x from sources.redhat.com/cygwin. If you have a pre-1.1 version, you should deinstall this first. Choose DOS text file type.
Create C:/Temp if it doesn't already exist; substitute the drive you installed Cygwin on for C:.
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.
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:
PATH | System | Add C:\usr\bin. This should come before the Windows system directories (e.g. \WINNT\system32). | |
SHELL | User | C:/usr/bin/bash. | |
HOME | User | Set to point to your home directory (normally under C:/WINNT/Profiles on Win2k). This is where, for example, bash will look for your .bashrc file. | |
MAKE_MODE | User | Set to UNIX. If you don't do this you get very weird messages when you type make, such as:
| |
TMPDIR | User | Set to C:/Temp. 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:
|
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.
Download the latest GHC distribution:
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 (e.g. /ghc/ghc-4.08/bin ). You need to do this in order to bring the various GHC binaries into scope.
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$ ghc -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 9).
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.
Symlinks only work under Cygwin (Section 2.1.2.1), so binaries not linked to the Cygwin DLL, in particular those built for Mingwin, will not work with symlinks.
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.