Installing Gnucash on Leopard

Gnucash is an open source accounting program for personal and small business use. When looking for a simple way to do the books for my company I came across it. I could easily install it under Ubuntu, but I really wanted to run it under OS X as well. Luckily it has been ported by both Fink and MacPorts.

I decided to try the MacPorts distribution but this did not install straight away under Leopard (10.5.2). I did get it running after some tweaks however.

Step by step:

I had Xcode and X11 already installed (in fact X11 appears to be installed by default on Leopard).

I installed MacPorts and asked it to update itself:
sudo port selfupdate
ok, nothing to be done as it was already the latest version.
Next:
sudo port install gnucash
This starts downloading and compiling half the universe in dependencies as Gnucash needs quite a bit of supporting software.
It looked like it was working, but then it stopped at the python hashlib:

---> Fetching py25-hashlib
---> Verifying checksum(s) for py25-hashlib
---> Extracting py25-hashlib
---> Configuring py25-hashlib
---> Building py25-hashlib with target build
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-hashlib/work/Python-2.5.2/Modules" && /opt/local/bin/python2.5 setup.py build " returned error 1
Command output: running build
running build_ext
building '_hashlib' extension
creating build
creating build/temp.macosx-10.3-i386-2.5
-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/include -I/opt/local/include/python2.5 -c _hashopenssl.c -o build/temp.macosx-10.3-i386-2.5/_hashopenssl.o
unable to execute -DNDEBUG: No such file or directory
error: command '-DNDEBUG' failed with exit status 1

I tried to find out where it had gone wrong, but I could not find anything. In an attempt to get more information I decided to install the py25-hashlib dependency manually:

sudo port install py25-hashtable

To my surprise this succeeded after which I continued the Gnucash install. I think that sudo had timed out due to the lengthy install.

The next point it stops at is gtk2 due to a missing /usr/X11/lib/libXrandr.2.0.0.dylib.
Leopard 10.5.2's X11 ships with a newer version of this library (2.1.0) and only has a symlink for libXrandr.2.dylib. Earlier versions had 2.0.0. Either the MacPorts need to specify version 2 or Apple needs to add symlinks to earlier versions.
Simply creating a symlink from /usr/X11/lib/libXrandr.2.1.0.dylib to 2.0.0 solves this problem:

sudo ln -s libXrandr.2.1.0.dylib libXrandr.2.0.0.dylib

---> Building gtk2 with target all
---> Staging gtk2 into destroot
---> Installing gtk2 2.12.9_0+x11
---> Activating gtk2 2.12.9_0+x11
---> Cleaning gtk2

Then I got a final error about a conflict with perl:

---> Activating p5-getopt-long 2.37_0
Error: Target org.macports.activate returned: Image error: /opt/local/lib/perl5/5.8.8/Getopt/Long.pm is being used by the active perl5.8 port. Please deactivate this port first, or use the -f flag to force the activation.

Once again I just tried to install p5-getopt-long separately (which gave me the message that it was already installed) and restarted the install for Gnucash.

The install finished succesfully and Gnucash ran directly from the commandline. To run it with dutch localization from the dock I added a small shell script to my Favourite Apps folder:

#!/bin/sh
cd /tmp
env LANG=nl_NL gnucash

That's it!