Difference between revisions of "Gtk2Hs"

From HaskellWiki
Jump to navigation Jump to search
(Use of the GTK+ OS X Framework)
Line 19: Line 19:
 
=== Mac OS X ===
 
=== Mac OS X ===
   
=== Using the GTK+ OS X Framework ===
+
==== Using the GTK+ OS X Framework ====
   
 
This explains how to install Gtk2Hs on Macs using the native [http://www.gtk-osx.org/ 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 [http://www.gtk-osx.org/ GTK+ OS X Framework], most notably support for Glade. It does include support for Cairo, though.
 
This explains how to install Gtk2Hs on Macs using the native [http://www.gtk-osx.org/ 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 [http://www.gtk-osx.org/ GTK+ OS X Framework], most notably support for Glade. It does include support for Cairo, though.

Revision as of 02:45, 4 March 2009

What is it?

Gtk2Hs is a Haskell binding to Gtk+ 2.x. Using it, one can write Gtk+ based applications with GHC.

Homepage

http://haskell.org/gtk2hs/

Status

It currently works with Gtk+ 2.0 through to 2.8 on Unix, Win32 and MacOS X. The widget function coverage is almost complete, only a few minor bits and pieces are missing.

It currently builds with ghc 5.04.3 through to 6.8.2

Installation Notes

Mac OS X

Using the 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/GLib.framework/Resources/dev/lib/pkgconfig:\ 
     /Library/Frameworks/Gtk.framework/Resources/dev/lib/pkgconfig ./configure --disable-gio
  1. Build with
     make
  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.

Article as of Mid 2008

Installing Gtk2Hs on Mac requires some finesse, at least until Haskell Libary Platform is built or ghc-6.8.3 is available in macports. (These are planned for late 2008.)

sudo port instll glade3 libglade2 gstreamer gst-plugins-base gtksourceview cairo librsvg gtkglext firefox
  • Update PKG_CONFIG_PATH (for libraries)
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/local/lib/pkgconfig
  • Update ghc to use macports libs: Edit your main ghc driver program and change the last line to:
exec $GHCBIN $TOPDIROPT ${1+"$@"} -L/opt/local/lib -I/opt/local/include
./configure --enable-docs --enable-profiling

...

**************************************************
* Configuration completed successfully.           
*                                                 
* The following packages will be built:           
*                                                 
* glib          : yes                             
* gtk           : yes                             
* glade         : yes              
* cairo         : yes                 
* svgcairo      : yes              
* gtkglext      : yes              
* gconf         : yes                 
* sourceview    : yes            
* mozembed      : yes              
* soegtk        : yes                             
* gnomevfs      : yes              
* gstreamer     : yes             
* documentation : yes                    
*                                                 
* Now do "(g)make" followed by "(g)make install"
**************************************************
  • Build and Install:
make 
sudo make install

Recent experiences

I successfully installed the latest version on Mac OS 10.5 by:

  • Installing Macports.
  • sudo port install ghc
  • sudo port install gtk2hs - which does not complete successfully. It does however, install the appropriate dependencies. Note that there are so many, you may need to install a couple of times due to time outs etc.. The build of Gtk2HS will fail, but that is ok - continue as below.
  • Remove the build directory under /opt/.../build/gtk2hs
  • Download Gtk2Hs via darcs as per the gtk2hs download instructions
  • do a sudo port install automake
  • do a sudo port install alex
  • do a sudo port install happy (Note this also fails and must be built from source. See the Happy page for details.)
  • Follow the build instructions on the the gtk2hs download page. I would suggest using ./configure --prefix=/opt/local to get it in the same place as ports - personal preference though.

Good luck - as usual, your mileage may vary.

Demos

OpenGL and Gtk2Hs

Gtk2Hs/Demos/GtkGLext/hello.hs

Gtk2Hs/Demos/GtkGLext/terrain.hs requires Gtk2Hs/Demos/GtkGLext/terrain.xpm

FAQs

These are links to FAQS on the main site.