Skip to content

Instantly share code, notes, and snippets.

@kowey
Forked from cartazio/gist:1655271
Created April 19, 2012 10:29
Show Gist options
  • Save kowey/2420144 to your computer and use it in GitHub Desktop.
Save kowey/2420144 to your computer and use it in GitHub Desktop.
Haskell GTK on 64 bit MacOS X

Notes

  • on lion (and snow leopard i suppose), make sure you are using a 64 bit install of ghc. Also, unless you are suggesting an edit to these directions, please go ask people on the relevant mailing list or wiki for help :)
  • Tested on ghc 7.2.2, assumes you have standard developer things installed on mac, like x11 and stuff
  • Also tested on GHC 7.0.4 (Haskell Platform) with XCode 4.3.
  • These notes were originally brought to you by Carter Schonwald; the “I” probably refers to him. Eric Kow will refer to himself in the third person).

GHC 7.4.x

  • gtk2hs 0.12.2 won't build with ghc 7.4.1, but the current darcs repo for gtk2hs does build
  • on 7.4 there seems to be a problem when in ghci and drawing to a window, but not when rendering to pdf. I don't know why this is, but if you do, let me know. I'll update this as i have more info

Steps

  1. Install gtk and cairo via HomeBrew

    brew install glib cairo gtk gettext fontconfig
    brew deps gtk # see below
    brew deps gtk | xargs brew link
    brew link cairo gettext fontconfig
    gtk-demo # just to see what happens
    

    Brew may complain, who cares, this makes your life easier (at least if you're living in a haskell world :p )

    NOTE: you will need to make sure that all these Brew libs are built, and linked in

  2. Download libfreetype

  3. Unpack libfreetype, and then run

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

    This will install the static and dynamic library files for lib freetype in /usr/local/ (../include and ../lib) , which is what you'll want, though this will contribute to brew doctor complaining, but again, this is the easiest way. Eric Kow has added stow to this mix because he thinks that making this easily reversible may be a good thing.

  4. Install Haskell gtk

     cabal install gtk2hs-buildtools 
     cabal install gtk
    

    This should work sans complaints!

  5. Install something using Cairo, eg, this plott.hs

     cabal install chart-gtk
     ghc --make plott.hs # see link above
     ./plott
    

    Try out some other cool libraries like diagrams!

More information

  • brew deps gtk on Eric Kow's machine

    $ brew deps gtk
    atk
    cairo
    gdk-pixbuf
    gettext
    glib
    jasper
    jpeg
    libffi
    libtiff
    pango
    pixman
    pkg-config
    xz
            
    $ brew deps gtk | xargs brew link
    Warning: Already linked: /usr/local/Cellar/atk/2.2.0
    Linking /usr/local/Cellar/cairo/1.10.2... 23 symlinks created
    Warning: Already linked: /usr/local/Cellar/gdk-pixbuf/2.24.1
    Linking /usr/local/Cellar/gettext/0.18.1.1... 181 symlinks created
    Warning: Already linked: /usr/local/Cellar/glib/2.30.3
    Warning: Already linked: /usr/local/Cellar/jasper/1.900.1
    Warning: Already linked: /usr/local/Cellar/jpeg/8d
    Linking /usr/local/Cellar/libffi/3.0.11... 9 symlinks created
    Warning: Already linked: /usr/local/Cellar/libtiff/3.9.5
    Warning: Already linked: /usr/local/Cellar/pango/1.28.4
    Warning: Already linked: /usr/local/Cellar/pixman/0.24.4
    Warning: Already linked: /usr/local/Cellar/pkg-config/0.25
    Warning: Already linked: /usr/local/Cellar/xz/5.0.3
    
    $ brew link cairo gettext fontconfig
    Warning: Already linked: /usr/local/Cellar/cairo/1.10.2
    Warning: Already linked: /usr/local/Cellar/gettext/0.18.1.1
    Linking /usr/local/Cellar/fontconfig/2.8.0... 241 symlinks created
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment