HomeBrew OS X El Capitan (64 bit, last checked 2016-08)

3. Set an environment variable to allow pkg-config to find the file gtk+-2.0.pc (mine is located at /usr/local/lib/pkgconfig):

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:

4. Install Cabal packages. The packages alex and happy are dependencies of dependencies of ghk2hs-buildtools. For some reason, they must be installed separately prior to installing gtk2hs-buildtools. The same goes for glib with respect to gtk. If they are not installed separately, compiling them fails. Make sure you install the gtk package with the flag -f have_quartz-gtk. Otherwise compiling gtk will fail.

At the time of writing, the versions installed with these commands are alex-3.1.7, happy-1.19.5, gtk2hs-buildtools-0.13.2.1, glib-0.13.4.0, gtk-0.14.5.

HomeBrew OS X Mavericks (64 bit, last checked 2014-05)

These instructions are an update of the HomeBrew installation shown below (2008) for Mavericks. Make sure that the system you are using has the 64bit version of the Haskell platform installed. Unfortunately, if you have an older 32bit version these instructions will work but all the programs using gtk will fail to compile.

1. Install XQuartz (download) at the time these instruction were written version 2.7.5 worked.
Make sure to logout and login again.

Detailed instructions

Install gtk, cairo, etc. from MacPorts like this (note that the +universal is needed; if you already installed gtk or one of its dependencies, it is recommended you reinstall those as detailed in the NB at the end of this section).

sudo port install gtk +universal

Go to the directory where gtk2hs is untarred and run

./configure --disable-split-objs --disable-gio
make
sudo make install

Alternatively, if you wish to follow the Mac OS X style of directory layout, you can use this configure command instead:

Right now you should be able to run the demos. Unfortunately, to build any libraries depending on Gtk2Hs, such as Chart, you need to edit one more file. You will need to find package.conf for your installed GHC by running

ghc-pkg list

In the output you will see the full directory to your package.conf file. In this file, you need to search for "gthread", and everywhere you can find it, add "/opt/local/lib" (with quotes) to the libraryDirs array before it.

If all went well, it should be properly installed now.

NB: If compiling fails with architecture errors for certain dynlibs, you need to reinstall the packages these dynlibs belong to with +universal by doing

Edit /opt/local/macports/variants.conf and add +universal to the end of this file

sudo port selfupdate

sudo port sync

sudo port upgrade --force installed

GTK+ OS X Framework

This explains how to install Gtk2Hs on Macs using the native GTK+ OS X Framework, a port of GTK+ to the Mac that does not depend on X11, and hence, is better integrated into the Mac desktop - i.e., menus actually appear in the menu bar, where they belong. It also avoids the often tedious installation of GTK+ via MacPorts. However, it misses support for optional Gtk2Hs packages that are currently not supported by the GTK+ OS X Framework, most notably support for Glade. It does include support for Cairo, though.