Sunday, April 17, 2011

Installing gtk2hs 0.12 for the latest Haskell Platform on the Windows 7

This post only comments the original tutorial from and describes extra action, one should perform to successfully install the Gtk bindings to Haskell without MinGW.

So, steps, you should perform:

  1. Read the original documentation on how to install Haskell for Windows

  2. Download all required files, mentioned im this document

  3. Install the Gtk to the location without spaces in the filenames. So the default location (C:\Program Files\Gtk+) won't work.

  4. Run command-line prompt, fill the INCLUDE and PKG_CONFIG_PATH with correct paths to Gtk+ and libxml2.

  5. run cabal install --ghc-option=-DCABAL_VERSION_MINOR=10 gtk

This is not all.

Now, some packages fails to register with error:

Registering cairo-0.12.0...
setup.exe: internal error: unexpected package db stack: [UserPackageDB]

This is because of bug (or mistake?) in Gtk2hsSetup.hs. So for these packages you should unpack them (e.g. cabal unpack cairo), move to the unpacked directory and change the following code in the Gtk2hsSetup.hs (line 199 of the file):

installedPkgInfo pkg lbi inplace [packageDb]
installedPkgInfo pkg lbi inplace packageDb


installedPkgInfo pkg lbi inplace (withPackageDB lbi)
installedPkgInfo pkg lbi inplace packageDb

Than, in the package root directory type:

cabal install --ghc-option=-DCABAL_VERSION_MINOR=10

Other errors I've faced with, and the solutions

Error in compiling pango package, the compiler couldn't find glib/glib.h file.

In the file pango-0.12.0\Graphics\Rendering\Pango\Struts.hsc change

#include <glib/glib.h>


#include <glib.h>

Error in compiling gio package, some names aren't defined (wmDriveStopButton, DriveStartStopType, DriveStartFlags)

This is because in the module exports these names are present, but defined in a body with macro:


My solution, is to wrap the definitions of these exports in the same macro. Fortunately this will not break the compilation.

After all these steps you should have a working installation of the Gtk2Hs. To check this, you could build and run examples from the gtk-0.12.0\demo directory.