1 Windows

1.1 Haskell Build System

You will need at least GHC and cabal-install. The simplest way to get these is to install the Haskell Platform. You will need to add cabal-install's executable directory to your %PATH% (it will tell you which path to add in a warning after you install your first executable there). See #Changing Environment Variables for details on how to do this.

1.2 GTK Libraries

Download an all-in-one bundle from the Gtk+ website. Unpack the bundle to a path that does not have spaces in it, and add the /bin directory created by unpacking to your %PATH%. Important points:

Get an all-in-one bundle. Do not install each of the packages separately.

Do not install the bundle to a path that has spaces in it.

Do not get the 2.16 bundle.

You can check that you have done everything in this step correctly by opening a command prompt and entering

pkg-config --cflags gtk+-2.0

If you see some compiler flags that contain the path into which you have installed the binary bundle, you are okay.

1.3 Gtk2Hs Bindings

This step should be as easy as running

cabal update
cabal install gtk2hs-buildtools
cabal install gtk

After installing gtk2hs-buildtools, make sure that gtk2hsC2hs is in a directory that is on your %PATH%.

1.4 Changing Environment Variables

The installation process involves modifying (or, if necessary, adding) the %PATH% environment variable. This subtopic describes how to do this. The %PATH% variable is a ';'-separated list of directories.

1.4.1 Command Prompt

You can see and modify variables with echo and set:

echo %PATH%
set PATH=dir1;dir2;...

1.4.2 Windows XP GUI

Start -> Control Panel -> System -> Advanced -> Environment Variables

In the top window, click "New" to add a variable or "Edit" to modify an existing one.

1.4.3 Windows 7 GUI

Click on the Windows symbol on the bottom-left where "Start" used to be

Choose Computer -> Properties -> Advanced System Settings

In the top window, click "New" to add a variable or "Edit" to modify an existing one.

1.5 Unzipping

There are many good tools for extracting zip archives on Windows. If you don't have one already, 7-zip is a fine choice to install. You can extract a file with a command like

1.6 Installing darcs

2 Linux

2.1 Preferred Way: Via Package Manager

You should check if your package manager already has gtk2hs, as this is the easiest and most reliable way to get everything installed. Below is a short list of package names for some distributions (feel free to add your favorite).

2.2 From Source

First install the dependencies: a Haskell build system and the Gtk+ libraries. For the build system, you need at least GHC and cabal-install; for the Gtk+ libraries you will need (the development versions of) glib, gio, cairo, pango, and gtk. The names of the appropriate packages are listed below for some distributions (feel free to add your favorite).

4 FreeBSD

5 Appendix

5.1 Supported Versions

The most recent release of Gtk2Hs was tested on the a variety of systems. Below we offer two kinds of statistics; the second thing we give is a list of system configurations on which the minimal gtk2hs installation described above has been tested. (Please feel free to add your system configuration if you build gtk2hs.) Above that, we list the versions of each component for which some system configuration successfully built gtk2hs, with an asterisk marking those that are officially supported. Any system configuration containing officially supported versions of each component should be able to build gtk2hs successfully; please report a bug if you find this not to be true!

5.1.1 Operating System

Windows XP*

Ubuntu 12.10*

Fedora 17*

5.1.2 Gtk+

2.12*

2.14*

2.18*

2.20*

2.22*

2.24*

5.1.3 GHC

7.0*

7.2*

7.4*

7.6*

5.1.4 Tested Configurations

gtk-0.12.4:

Windows XP, Gtk+ 2.12, GHC 7.6

Windows XP, Gtk+ 2.14, GHC 7.6

Windows XP, Gtk+ 2.18, GHC 7.6

Windows XP, Gtk+ 2.20, GHC 7.6

Windows XP, Gtk+ 2.22, GHC 7.6

Windows XP, Gtk+ 2.24, GHC 7.6

Windows XP, Gtk+ 2.24, GHC 7.4

Windows XP, Gtk+ 2.24, GHC 7.2

Windows XP, Gtk+ 2.24, GHC 7.0

Fedora 17, Gtk+ 2.24, GHC 7.6

Debian sid, Gtk+ 2.24, GHC 7.6

gtk-0.12.3:

Ubuntu 12.10, Gtk+ 2.24, GHC 7.4

Windows 7, Gtk+ ??, GHC ??

5.2 Going Beyond Minimal: All Available Packages

There are many packages available. The basic one installed by the above instructions are:

One benefit of getting the source repository is that there are demos available in each package's demo directory. For example, you can run gtk's Hello World example by:

cd gtk2hs/gtk/demo/hello
ghc World
./World

There are also Makefiles in each directory if you have a suitable make installation.

5.4 Getting the Oldest and Moldiest

There are bundles of some very old versions available on the SourceForge downloads page. For newer versions, follow the instructions for installing darcs for your operating system. You can then get version x.y.z with the command

darcs get -t x.y.z http://code.haskell.org/gtk2hs

5.5 Troubleshooting

5.5.1 glade.h is not found

The symptom is this error message:

gtk2hsC2hs.exe : glade/glade.h: File does not exist

Probably this means that instead of installing the GTK/Glade bundle you installed them separately. The Gtk+/glade bundle comes with the "include/libglade-2.0" containing a number of header files. For some reason this directory is not included in stand-alone Gtk+ and glade installers. Install the bundle and add this directory to the INCLUDE environment variable.

5.5.2 cabal cannot find gtk2hsC2hs

Either you forgot to install gtk2hs-buildtools, or you have not yet put cabal's executable directory in your path. Default directories are

5.5.3 "Spinner" errors while trying to compile the "notebook" demo

The symptom is errors like the following:

[1 of 1] Compiling Main ( Notebook.hs, Notebook.o )
Notebook.hs:14:35:
Not in scope: type constructor or class `Spinner'
Notebook.hs:78:13: Not in scope: `spinnerNew'
Notebook.hs:101:2: Not in scope: `spinnerStart'
Notebook.hs:109:2: Not in scope: `spinnerStop'

The Spinner widget first appears in Gtk+-2.22, so this will happen if you installed an older version of Gtk+.

5.6 Uninstalling

Uninstallation is currently ill-supported. You can unregister packages with GHC using ghc-pkg unregister, and the installed files can be manually deleted from GHC's local directories, but cabal does not yet support automatic uninstallation.