Difference between revisions of "Gtk2Hs/Mac"

From HaskellWiki
Jump to navigation Jump to search
 
(39 intermediate revisions by 8 users not shown)
Line 9: Line 9:
 
!|GHC
 
!|GHC
 
!|Haskell Platform
 
!|Haskell Platform
  +
|-
  +
|2016-08
  +
|Intel 64-bit
  +
|El Capitan 10.11.6, Xcode Version 7.3.1 (7D1014)
  +
|gtk+/2.24.30 (Homebrew)
  +
|0.13.2.1
  +
|8.0.1 (Homebrew)
  +
|-
  +
|-
  +
|-
  +
|2014-05
  +
|Intel 64-bit
  +
|Mavericks - 10.9.2, Xcode Version 5.1.1
  +
|HomeBrew
  +
|0.12.5.7
  +
|7.6.3
  +
|2013.2.0.0 for Mac OS X, 64 bit
  +
|-
  +
|-
  +
|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
 
|2011-08
|Intel 32 bit
+
|Intel 32-bit
 
|Snow Leopard
 
|Snow Leopard
|2.24.5 HomeBrew
+
|2.24.5 Homebrew
 
|gtk-0.12.0
 
|gtk-0.12.0
 
|7.0.3
 
|7.0.3
Line 19: Line 53:
 
|-
 
|-
 
|2011-03
 
|2011-03
|Intel 64 bit
+
|Intel 64-bit
 
|Leopard
 
|Leopard
 
|MacPorts
 
|MacPorts
 
|
 
|
 
|6.10
 
|6.10
  +
|
 
|}
 
|}
   
== HomeBrew (last checked 2011-08) ==
+
== HomeBrew OS X El Capitan (64 bit, last checked 2016-08) ==
  +
1. Install XQuartz (version 2.7.9 at the time of writing):
  +
<pre>
  +
brew cask install xquartz
  +
</pre>
  +
  +
2. Install GTK and the required libraries
  +
<pre>
  +
brew install glib cairo gtk gettext fontconfig freetype
  +
</pre>
  +
  +
3. Set an environment variable to allow <tt>pkg-config</tt> to find the file <tt>gtk+-2.0.pc</tt> (mine is located at <tt>/usr/local/lib/pkgconfig</tt>):
  +
<pre>
  +
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:
  +
</pre>
  +
  +
4. Install Cabal packages. The packages <tt>alex</tt> and <tt>happy</tt> are dependencies of dependencies of <tt>ghk2hs-buildtools</tt>. For some reason, they must be installed separately prior to installing <tt>gtk2hs-buildtools</tt>. The same goes for <tt>glib</tt> with respect to <tt>gtk</tt>. If they are not installed separately, compiling them fails. Make sure you install the <tt>gtk</tt> package with the flag <tt>-f have_quartz-gtk</tt>. Otherwise compiling <tt>gtk</tt> will fail.
  +
<pre>
  +
cabal install alex happy
  +
cabal install gtk2hs-buildtools
  +
cabal install glib
  +
cabal install gtk -f have-quartz-gtk
  +
</pre>
  +
  +
At the time of writing, the versions installed with these commands are <tt>alex-3.1.7</tt>, <tt>happy-1.19.5</tt>, <tt>gtk2hs-buildtools-0.13.2.1</tt>, <tt>glib-0.13.4.0</tt>, <tt>gtk-0.14.5</tt>.
  +
  +
== HomeBrew OS X Mavericks (64 bit, last checked 2014-05) ==
  +
  +
These instructions are an update of the HomeBrew installation shown below (2008) for Mavericks. Make sure that the system you are using has the 64bit version of the Haskell platform installed. Unfortunately, if you have an older 32bit version these instructions will work but all the programs using gtk will fail to compile.
  +
  +
1. Install XQuartz ([http://xquartz.macosforge.org/landing/ download]) at the time these instruction were written version 2.7.5 worked.
  +
Make sure to logout and login again.
  +
  +
2. Install the gtk library and dependencies
  +
  +
<pre>
  +
brew install glib cairo gtk gettext fontconfig
  +
</pre>
  +
  +
3. Build freetype by hand ([http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz download])
  +
<pre>
  +
tar -xzvf freetype-2.5.3.tar.gz
  +
cd freetype-2.5.3
  +
./configure
  +
make
  +
make install
  +
</pre>
  +
  +
Verify whether gtk installed correctly by executing gtk-demo.
  +
If the window does not open you might have forgotten to logout and login.
  +
<pre>
  +
gtk-demo
  +
</pre>
  +
  +
4. Install Haskell GTK with gcc 4.8, it might work with other versions of gcc that you already have installed. However, it will not work with gcc versions <= 4.2.
  +
<pre>
  +
cabal install gtk2hs-buildtools
  +
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
  +
brew tap homebrew/versions
  +
brew install gcc48
  +
cabal install --with-gcc=gcc-4.8 gtk
  +
</pre>
  +
  +
== HomeBrew (64 bit, last checked 2012-08) ==
  +
  +
These instructions come from [https://gist.github.com/2420144 a gist by Carter Schonwald]
  +
  +
1. Install the gtk library and dependencies
  +
  +
<pre>
  +
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
  +
</pre>
  +
  +
2. Build freetype by hand ([http://sourceforge.net/projects/freetype/files/freetype2/2.4.8/freetype-2.4.8.tar.bz2/download?use_mirror=iweb download])
  +
  +
<pre>
  +
brew install stow
  +
mkdir /usr/local/stow
  +
cd freetype-2.4.8
  +
./configure --prefix /usr/local/stow/freetype-2.4.8
  +
make
  +
make install
  +
cd /usr/local/stow
  +
stow freetype-2.4.8
  +
</pre>
  +
  +
3. Install Haskell GTK
  +
<pre>
  +
cabal install gtk2hs-buildtools
  +
cabal install gtk
  +
</pre>
  +
  +
4. Update for Mountain Lion (OSX 10.8)
  +
  +
This OS release uses xquartz project X11 implementation, that may yield errors while building the package.
  +
  +
In the above step 3 (cabal install gtk) I had errors that were resolved by:
  +
  +
4.1 Fixing any detail reported by "brew doctor"
  +
  +
4.2. Accepting the XCode 4.4 command line tool's license:
  +
<pre>sudo xcodebuild -license</pre>
  +
  +
4.3. Setting pkg-config search path to:
  +
  +
<pre>
  +
export PKG_CONFIG_PATH=~/Source/gtk/source/libpng-1.4.8/:/opt/X11/lib/pkgconfig
  +
</pre>
  +
  +
4.4. Building (as cited in gtk2hs mac instructions) with
  +
<pre>
  +
cabal install gtk -fhave-quartz-gtk
  +
</pre>
  +
  +
== HomeBrew (32 bit, last checked 2011-08) ==
   
 
<pre>
 
<pre>
Line 33: Line 186:
 
gtk-demo
 
gtk-demo
 
</pre>
 
</pre>
If the gtk-demo appears to work, proceed to the rest of the ThreadScope install.
+
If the gtk-demo appears to work, proceed to the rest of the gtk2hs install.
   
 
=== Troubleshooting ===
 
=== Troubleshooting ===
Line 41: Line 194:
 
Try running the gtk-demo program. Does it also fail?
 
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:<pre>brew update brew install gtk+</pre>
+
If so, did you try updating your port? For example, if you are using Howebrew try:
   
  +
<pre>
Then try gtk-demo again and finally<pre>cabal install --renistall gtkhs</pre>
 
  +
brew update
  +
brew install gtk+
  +
</pre>
  +
  +
Then try gtk-demo again and finally
  +
  +
<pre>cabal install --renistall gtk</pre>
   
 
It may be worthwhile to try a [http://projects.haskell.org/gtk2hs/documentation/#hello_world gtkhs helloworld]
 
It may be worthwhile to try a [http://projects.haskell.org/gtk2hs/documentation/#hello_world gtkhs helloworld]
   
== Snow Leopard (10.6) 64bit, MacPorts (2011-03-10) ==
+
== MacPorts (last checked 2011-03-10) ==
   
* Install MacPorts (macports.org)
+
* Install [http://www.macports.org/ MacPorts]
* Add +universal to /opt/local/etc/macports/variants.conf (not needed on 32bit)
+
* Add <tt>+universal</tt> to <tt>/opt/local/etc/macports/variants.conf</tt> (not needed on 32bit)
* execute: sudo port install ghc gtk2 gvfs cairo librsvg libglade2 gtkglext gtksourceview2 && sudo port install gtk2hs -universal
+
* execute:<pre>sudo port install ghc gtk2 gvfs cairo librsvg libglade2 gtkglext gtksourceview2 && sudo port install gtk2hs -universal</pre>
   
  +
=== Detailed instructions ===
== Using MacPorts and Snow Leopard ==
 
   
 
This explains how to install Gtk2Hs-0.10.1 on Mac OS X 10.6 Snow Leopard, in combination with GTK+ from MacPorts.
 
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 [http://hackage.haskell.org/platform/ Haskell Platform] for Mac
 
* Install the [http://hackage.haskell.org/platform/ Haskell Platform] for Mac
* Download gtk2hs from [http://www.haskell.org/gtk2hs/ gtk2hs website] and untar it.
+
* Download gtk2hs from [http://www.haskell.org/gtk2hs/ 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).
+
* Install gtk, cairo, etc. from MacPorts like this (note that the <tt>+universal</tt> 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
+
<pre>sudo port install gtk +universal</pre>
* go to the directory where gtk2hs is untarred and run
+
* Go to the directory where gtk2hs is untarred and run
:::./configure --disable-split-objs --disable-gio
+
<pre>./configure --disable-split-objs --disable-gio
:::make
+
make
:::sudo make install
+
sudo make install</pre>
   
 
Alternatively, if you wish to follow the Mac OS X style of directory layout, you can use this configure command instead:
 
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/username/.ghc/i386-darwin-6.10.4/package.conf --prefix=/Users/username/Library/Haskell/packages/gtk2hs --disable-split-objs --disable-gio
+
<pre>./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</pre>
   
Where username is your username ofcourse. Right now you should be able to run the demos. Unfortunately, to build any libraries depending on gtk2hs, such as [http://hackage.haskell.org/package/Chart/ Chart], you need to edit one more file. You will need to find "package.conf" for your ghc by doing
+
Right now you should be able to run the demos. Unfortunately, to build any libraries depending on Gtk2Hs, such as [http://hackage.haskell.org/package/Chart/ Chart], you need to edit one more file. You will need to find <tt>package.conf</tt> for your installed GHC by running
  +
:::ghc-pkg list
 
  +
<pre>ghc-pkg list</pre>
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.
 
  +
  +
In the output you will see the full directory to your <tt>package.conf</tt> file. In this file, you need to search for "gthread", and everywhere you can find it, add <tt>"/opt/local/lib"</tt> (with quotes) to the <tt>libraryDirs</tt> array before it.
   
 
If all went well, it should be properly installed now.
 
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
+
NB: If compiling fails with architecture errors for certain dynlibs, you need to reinstall the packages these dynlibs belong to with <tt>+universal</tt> by doing
  +
:::sudo port upgrade packagename --enforce-variants +universal
 
  +
<pre>sudo port upgrade packagename --enforce-variants +universal</pre>
  +
 
Alternatively, and this is recommended, you can follow the steps on [http://passingcuriosity.com/2009/haskell-on-snow-leopard/ Haskell On Snow Leopard Blogpost] to immediately add the universal variant of each package:
 
Alternatively, and this is recommended, you can follow the steps on [http://passingcuriosity.com/2009/haskell-on-snow-leopard/ Haskell On Snow Leopard Blogpost] to immediately add the universal variant of each package:
# Edit /opt/local/macports/variants.conf and add +universal to the end of this file
+
# Edit <tt>/opt/local/macports/variants.conf</tt> and add <tt>+universal</tt> to the end of this file
 
# sudo port selfupdate
 
# sudo port selfupdate
 
# sudo port sync
 
# sudo port sync
# sudo port upgrade --force-installed
+
# sudo port upgrade --force installed
   
== Using the GTK+ OS X Framework ==
+
== GTK+ OS X Framework ==
   
 
This explains how to install Gtk2Hs on Macs using the native [http://gtk-osx.sourceforge.net/ 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://gtk-osx.sourceforge.net/ 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://gtk-osx.sourceforge.net/ 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://gtk-osx.sourceforge.net/ GTK+ OS X Framework], most notably support for Glade. It does include support for Cairo, though.

Latest revision as of 17:05, 14 April 2018

Known configurations

Date Arch OS GTK Gtk2Hs GHC Haskell Platform
2016-08 Intel 64-bit El Capitan 10.11.6, Xcode Version 7.3.1 (7D1014) gtk+/2.24.30 (Homebrew) 0.13.2.1 8.0.1 (Homebrew)
2014-05 Intel 64-bit Mavericks - 10.9.2, Xcode Version 5.1.1 HomeBrew 0.12.5.7 7.6.3 2013.2.0.0 for Mac OS X, 64 bit
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 OS X El Capitan (64 bit, last checked 2016-08)

1. Install XQuartz (version 2.7.9 at the time of writing):

brew cask install xquartz

2. Install GTK and the required libraries

brew install glib cairo gtk gettext fontconfig freetype

3. Set an environment variable to allow pkg-config to find the file gtk+-2.0.pc (mine is located at /usr/local/lib/pkgconfig):

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:

4. Install Cabal packages. The packages alex and happy are dependencies of dependencies of ghk2hs-buildtools. For some reason, they must be installed separately prior to installing gtk2hs-buildtools. The same goes for glib with respect to gtk. If they are not installed separately, compiling them fails. Make sure you install the gtk package with the flag -f have_quartz-gtk. Otherwise compiling gtk will fail.

cabal install alex happy
cabal install gtk2hs-buildtools
cabal install glib
cabal install gtk -f have-quartz-gtk

At the time of writing, the versions installed with these commands are alex-3.1.7, happy-1.19.5, gtk2hs-buildtools-0.13.2.1, glib-0.13.4.0, gtk-0.14.5.

HomeBrew OS X Mavericks (64 bit, last checked 2014-05)

These instructions are an update of the HomeBrew installation shown below (2008) for Mavericks. Make sure that the system you are using has the 64bit version of the Haskell platform installed. Unfortunately, if you have an older 32bit version these instructions will work but all the programs using gtk will fail to compile.

1. Install XQuartz (download) at the time these instruction were written version 2.7.5 worked. Make sure to logout and login again.

2. Install the gtk library and dependencies

brew install glib cairo gtk gettext fontconfig

3. Build freetype by hand (download)

tar -xzvf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure
make
make install

Verify whether gtk installed correctly by executing gtk-demo. If the window does not open you might have forgotten to logout and login.

gtk-demo

4. Install Haskell GTK with gcc 4.8, it might work with other versions of gcc that you already have installed. However, it will not work with gcc versions <= 4.2.

cabal install gtk2hs-buildtools 
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
brew tap homebrew/versions
brew install gcc48
cabal install --with-gcc=gcc-4.8 gtk 

HomeBrew (64 bit, last checked 2012-08)

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
gtk-demo

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
make install
cd /usr/local/stow
stow freetype-2.4.8

3. Install Haskell GTK

cabal install gtk2hs-buildtools 
cabal install gtk

4. Update for Mountain Lion (OSX 10.8)

This OS release uses xquartz project X11 implementation, that may yield errors while building the package.

In the above step 3 (cabal install gtk) I had errors that were resolved by:

4.1 Fixing any detail reported by "brew doctor"

4.2. Accepting the XCode 4.4 command line tool's license:

sudo xcodebuild -license

4.3. Setting pkg-config search path to:

export PKG_CONFIG_PATH=~/Source/gtk/source/libpng-1.4.8/:/opt/X11/lib/pkgconfig

4.4. Building (as cited in gtk2hs mac instructions) with

cabal install gtk -fhave-quartz-gtk

HomeBrew (32 bit, last checked 2011-08)

brew update 
brew install gtk+ libglade
gtk-demo

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

Troubleshooting

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
make
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/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.