« Big Lambda | Main | Compiling regex-posix in Haskell for Windows »

Installing Gtk2Hs on MacOS

After months of quiet yearning & frustration, I finally chewed into a big bullet and got Gtk2Hs installed on my Mac (OS 10.6.4 with GHC 6.12.3).

It was a long and harrowing affair. There were many confusing error messages. Ultimately, though, it was just a process of being patient with the various package managers and manually chasing down dependencies that are external to cabal. I had to use both Fink and MacPorts (and had to do lots of time-consuming update and selfupdate runs on these).

The Packages

Here are the packages I can remember having to install:

  • glib (from Fink)
  • gtk+2 (from Fink; NB -shlib and -dev packages)
  • freetype (??)
  • fontconfig (??)
  • cairo (from MacPorts)
  • pango (from MacPorts)

After all that, cabal install gtk just worked. I was able to run example programs from this Gtk2Hs tutorial and get the windows to pop up and work correctly.

Double-Fisting

Running Fink and MacPorts is like having bacon on your sausage; it's a little redundant and includes much cholesterol, but it's easy to do and feels good at the time. Why I did this, or felt I had to, is now lost to me as well.

Misc. Stumbling Blocks

It bears noting that gtk and gtk+ are essentially synonyms, so don't go hunting for one when you've got the other. On the other hand, a "2" suffix there is essential: gtk2 and gtk-2.0 have nothing to do with "gtk" or "gtk 1.x"; they're essentially different products.

Several times I thought I was set having installed, say, the gtk+2 and gtk+2-shlibs packages from Fink, only to receive a complaint that gtk+2.pc (the pkg-config data file which other packages use to locate gtk+2) was missing, which made me gnash my teeth. The fix was to also install gtk+2-dev, which apparently should be called gtk+2-without-which-nothing.

Wordsize Conundra

I've had a number of minor 32- vs 64-bit problems with GHC. It seems that Haskell Platform installs a 32-bit ghc. (Why would this be? GHC does run 64-bit on MacOS, doesn't it?). Sometimes package managers install fat versions of libraries, which is good, but when using both Fink and MacPorts, a library with 64-bit-only versions might shadow the other.

Somewhere in the darkness, I had a problem with zlib being 64-bit and hence unusable, and I couldn't determine which library was using it in order to muck with it (it wasn't gtk itself, glib, nor the Haskell zlib bindings). This was fixed by un- and re-installing GHC via Haskell Platform, which entailed a minor version upgrade as well as perhaps clearing any strange customizations that I can't deny making to the 32-bitness of my GHC install.

(I'm surprised there's not a better system for managing such library flavors on OS X. Couldn't we keep separate system paths like /usr/local/lib64 and such? Or would this be a greater nightmare in itself?)

Apologies

I wish this were a more helpful document. If you try this soon, and hit a snag, let me know and I'll either remember how I resolved it, or try to add to what's here.

Comments

I have set this up on OS X. The best way I have found does not use fink, just macports. Ensure macports builds the 32-bit version and not just the 64-bit version by editing the macports configuration file to have "+universal" enabled. Ensure (e.g. by restarting from scratch) that everything macports builds had this flag in effect.

Use macports to get gtk2 and cairo and pango and glade (I am using the default X11 version of all of these). Also use macports to ensure the prerequisites of GHC are built.

Then I can build ghc against macports which ensures no conflicts later.

Then I can "cabal install gtk2hs" against macports and it works as it is supposed to.

I found this guide to be useful as well, it's pure macports again:
http://www.mail-archive.com/haskell-cafe@haskell.org/msg77164.html

Once gtk, and ghc (linked to macports libs) were both installed I had to use:

cabal install gtk2hs-buildtools
cabal install gtk

If memory serves, I had to download the gtk2hs-buildtools package manually.

Ah yes, I had to do gtk2hs-buildtools separately as well. THanks, Tom.

You should probably try homebrew: http://github.com/mxcl/homebrew

Heya i'm for the first time here. I found this board and I find It truly useful & it helped me out a lot. I hope to give something back and aid others like you aided me.

Heya i'm for the first time here. I found this board and I find It truly useful & it helped me out a lot. I hope to give something back and aid others like you aided me.

Hi there friends, how is everything, and what you desire to say on the topic of this article, in my view its actually amazing in favor of
me.

Appreciating the time and energy you put into your website and detailed information you provide.
It's awesome to come across a blog every once in a while that isn't the same unwanted rehashed information.
Excellent read! I've bookmarked your site and I'm adding your RSS feeds to my Google account.

Sweet blog! I found it while browsing on Yahoo
News. Do you have any tips on how to get listed in Yahoo News?
I've been trying for a while but I never seem to get there! Appreciate it

Howdy! This is my first visit to your blog! We are a group of volunteers and starting a
new initiative in a community in the same niche. Your blog provided us beneficial information to work on.
You have done a outstanding job!

What's up to all, how is the whole thing, I think every one is getting more from this web page, and your views are fastidious in support of new visitors.

Appreciate the recommendation. Let me try it out.

Post a comment