Skip to content

Instantly share code, notes, and snippets.

@cartazio
Created January 22, 2012 03:16
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cartazio/1655271 to your computer and use it in GitHub Desktop.
simple directions to install gtk haskell libs on OS X lion so that Everything works
NOTE: 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 :)
NOTE: gtk2hs 0.12.2 won't build with ghc 7.4.1, but the current darcs repo for gtk2hs does build
NOTE: 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
note that these directions probably can use some cleanup, but i'm choosing these steps so that rebuilding any haskell library doesn't require remembering ANYTHING :-)
(tested on ghc 7.2.2, assumes you have standard developer things installed on mac, like x11 and stuff)
1) cabal install gtk2hs-buildtools #(this should work with any haskell platform install)
2) brew install cairo gtk gettext fontconfig
3) brew link cairo gettext fontconfig and all the other dependencies listed for brew's gtk formula
this is best done with
by hand running brew link for each of the items in `brew deps gtk` along with fontconfig and gettext.
some of these will already linked, and some won't be, so this command makes it simpler
# brew will 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
4) download libfreetype, heres a URL you can use http://sourceforge.net/projects/freetype/files/freetype2/2.4.8/freetype-2.4.8.tar.bz2/download?use_mirror=iweb
5) unpack libfreetype, and then run
./configure ; make ; make install
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
6) cabal install gtk
this should work sans complaints!
now you can eg
cabal install chart-gtk
and run
this https://gist.github.com/1655252 example chart code either by building with ghc and running the executable
or by running main in ghc, and
or
try out some other cool libraries like diagrams!
@cartazio
Copy link
Author

It seems quite likely that the tricky detail about freetype (not having static libs by default) is a lurking reason why gtk has historically been tricky to use on the mac in particular

@johanjeuring
Copy link

I tried to follow these steps, but got

setup: The program pkg-config version >=0.9.0 is required but the version of
/opt/local/bin/pkg-config could not be determined.

Does that ring a bell?

This happens if I deactivate port libiconv. If ports libiconv is activated I get

Undefined symbols for architecture x86_64:
"_locale_charset", referenced from:
_localeEncoding in libHSbase-4.4.1.0.a(PrelIOUtils.o)

and a couple more.

@cartazio
Copy link
Author

johan: these directions are only indicated to work with mac homebrew and I can only help you if you in fact follow the directions as indicated exactly.

@johanjeuring
Copy link

It worked when I threw away all port stuff.

@cartazio
Copy link
Author

great!

@kowey
Copy link

kowey commented Apr 5, 2012

Thanks for this walkthrough. Could you clarify what the brew link step is about (#3), and why we wouldn't just do the default HomeBrew thing. Is this something related to freetype? What's wrong with using the Apple freetype?

I'd love to be able to update the Haskell wiki Gtk2hs Mac install instructions taking your walkthrough into account.

@cartazio
Copy link
Author

cartazio commented Apr 5, 2012

the link step is just to symlink those packages into usr/local/bin and usr/local/lib etc, because some of them default to being "keg only"

the problem with the apple freetype lib (which I assume you mean the one that comes with x11? ) is that it only provides the dylib (.dylib) and not the static lib (.so), and ghc currently doesn't really do dynamic linking by default on OS X.

So those are really two orthogonal issues, but I hope that answers your questions.

@cartazio
Copy link
Author

cartazio commented Apr 5, 2012

I can elaborate further if you like.

@kowey
Copy link

kowey commented Apr 6, 2012

Thanks for the explanations!

I'm still stuck on http://hackage.haskell.org/trac/gtk2hs/ticket/1241 it seems. Hmm!

@cartazio
Copy link
Author

cartazio commented Apr 6, 2012

did you make ; make install lib freetype?
you need to do that before building anything else....

@cartazio
Copy link
Author

cartazio commented Apr 6, 2012

I suspect thats related to the linking error I filed about 2 months ago for ghc, but have been to busy to try to come up with a reproducible minimal example of c code to replicate it

@kowey
Copy link

kowey commented Apr 13, 2012

Any chance you could dig up a link to that ticket? Thanks :-)

@kowey
Copy link

kowey commented Apr 13, 2012

(I had indeed built/installed freetype from src, only diff being that I put it in stow and stow'ed it to add the symlinks prior). Sorry for the late delayed response. I misread your question to think it was something I'd need some effort to figure out whether or not I'd done it.

@cartazio
Copy link
Author

ok, did you trash all the package which use gtk2hs and rebuild them?
also, once you do that, check if things run via ghci vs statically linked and compiled?
what happens when running the example programs?

@cartazio
Copy link
Author

@kowey, the linking error was that only one of the .so and .dylib version was available
also make sure that you're using the homebrew built version of all the libs.

@cartazio
Copy link
Author

@cartazio
Copy link
Author

I got a bit busy so i couldn't follow up on the ticket.
basically if the .dylib is available but the .so isn't, it seems that certain crazy crashing could happen, but I never concocted a simplified example to test this out in an easy to reproduce manner

@kowey
Copy link

kowey commented Apr 19, 2012

Woo! I'm pretty thrilled to report that after starting over (brew remove packages, unstowing libfreetype), I now have a working gtk2hs/cairo. Thanks for posting this and for your patience.

I must simply have overlooked a step or something (I remember brew remove complaining that some packages I wanted to remove weren't actually installed).

In case it helps, I've formatted your instructions and made them a bit more copy-and-paste friendly (see my fork). Hopefully a bit more foolproof against people like me, who tend to have trouble following instructions :-) Will think about adding this to Haskell wiki too

@cartazio
Copy link
Author

congrats and kudos

@hamishmack
Copy link

The last time I looked I could not see how to get Quartz support, Gtk+ 3 and WebKitGTK+ working with brew. For that reason I have been using MacPorts.

After installing MacPorts, I add this to my /opt/local/etc/macports/variants.conf file:

+gcc48 -x11 +no_x11 +quartz +gtk3

Then I run something like:

sudo port install webkit-gtk3 gnome-themes-standard gtksourceview3 gtk-osx-application

Then I build a version of GHC that uses the MacPorts libiconv and gmp by configuring the ghc build like this:

./configure --with-iconv-includes=/opt/local/include --with-iconv-libraries=/opt/local/lib --with-gmp-includes=/opt/local/include --with-gmp-libraries=/opt/local/lib --with-gcc=gcc-mp-4.8 --with-cpp=gcc-mp=4.8 --prefix=$HOME/ghc-7.8.4

Then I make sure that version of GHC is in my PATH and run:

cabal install gtk2hs-buildtools
cabal install webkitgtk3-javascriptcore gtksourceview3 gtk3-mac-integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment