From HaskellWiki
< Gtk2Hs
Revision as of 15:44, 19 April 2012 by EricKow (talk | contribs) (HomeBrew (64 bit, last checked 2012-04))

Jump to: navigation, search

Known configurations

Date Arch OS GTK Gtk2Hs GHC Haskell Platform
2012-04 Intel 64-bit Lion - 10.7.3, Xcode 4.3 HomeBrew 0.12.3 7.0.4 2011.3.0.0
2012-02 Intel 64-bit Lion - 10.7.3, Xcode 4.1 MacPorts darcs HEAD 2012-02-20 7.4.1 (built from source, 64-bit)
2011-08 Intel 32-bit Snow Leopard 2.24.5 Homebrew gtk-0.12.0 7.0.3 2011.2.0.1
2011-03 Intel 64-bit Leopard MacPorts 6.10

HomeBrew (64 bit, last checked 2012-04)

These instructions come from a gist by Carter Schonwald

1. Install the gtk library and dependencies

brew install glib cairo gtk gettext fontconfig
brew deps gtk # see below
brew deps gtk | xargs brew link
brew link cairo gettext fontconfig

2. Build freetype by hand (download)

brew install stow
mkdir /usr/local/stow
cd freetype-2.4.8
./configure --prefix /usr/local/stow/freetype-2.4.8
make install
cd /usr/local/stow
stow freetype-2.4.8

3. Install Haskell GTK

cabal install gtk2hs-buildtools 
cabal install gtk

HomeBrew (32 bit, last checked 2011-08)

brew update 
brew install gtk+ libglade

If the gtk-demo appears to work, proceed to the rest of the gtk2hs install.


Problem: Bus error

Try running the gtk-demo program. Does it also fail?

If so, did you try updating your port? For example, if you are using Howebrew try:

brew update
brew install gtk+

Then try gtk-demo again and finally

cabal install --renistall gtk

It may be worthwhile to try a gtkhs helloworld

MacPorts (last checked 2011-03-10)

  • Install MacPorts
  • Add +universal to /opt/local/etc/macports/variants.conf (not needed on 32bit)
  • execute:
    sudo port install ghc gtk2 gvfs cairo librsvg libglade2 gtkglext gtksourceview2 && sudo port install gtk2hs -universal

Detailed instructions

This explains how to install Gtk2Hs-0.10.1 on Mac OS X 10.6 Snow Leopard, in combination with GTK+ from MacPorts.

  • Install the Haskell Platform for Mac
  • Download gtk2hs from Gtk2Hs website and untar it.
  • 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
sudo make install

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

./configure --with-pkgconf=/Users/$USER/.ghc/i386-darwin-6.10.4/package.conf --prefix=/Users/$USER/Library/Haskell/packages/gtk2hs --disable-split-objs --disable-gio

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

sudo port upgrade packagename --enforce-variants +universal

Alternatively, and this is recommended, you can follow the steps on Haskell On Snow Leopard Blogpost to immediately add the universal variant of each package:

  1. Edit /opt/local/macports/variants.conf and add +universal to the end of this file
  2. sudo port selfupdate
  3. sudo port sync
  4. 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.

Here is how to install the library:

  1. Download and install GTK+ OS X Framework (this uses the standard Mac package installer).
  2. Install pkg-config, either by compiling it from source or via MacPorts.
  3. Download and unpack the Gtk2Hs tar ball from the Gtk2Hs download page (I tested 0.10.0).
  4. Configure with (you may want to remove the two backslashes and put everything on one line)
     env PKG_CONFIG_PATH=/Library/Frameworks/Cairo.framework/Resources/dev/lib/pkgconfig:\ 
     /Library/Frameworks/Gtk.framework/Resources/dev/lib/pkgconfig ./configure --disable-gio
  1. Build with
  1. Install (to /usr/local/ unless a --prefix option was passed to configure) with
     sudo make install

The library is now registered with the package database of the GHC you used for compiling.

NB: Thanks to Ross Mellgren for his post on the gtk2hs-users list that outlined the use of PKG_CONFIG_PATH.