Using SWT/GTK+ on Darwin

by Billy Biggs - vektor@dumbterm.net, 6 Aug 2005

I own a PowerBook G4 running Mac OS X that leads a dual life. Sometimes, it's just plain old OS X, but the rest of the time, it's a KDE desktop running under a fullscreen XFree86 session. I use fink but am thinking of switching to DarwinPorts.

For hacking around, I thought it would be useful to compile SWT/GTK+ against the GTK+ from fink. The port was trivial, and I'm thinking of merging the patch in upstream or getting it into fink/darwinports.

  1. Grab the SWT Binary and Source for SWT/GTK+ x86.
  2. Grab my small patch which sets up some of the paths and changes the extensions of the shared libraries from .so to .dylib or .jnilib as appropriate.
  3. Unzip it somewhere, remove the x86 binaries, unzip the source, apply the patch, and build using the make_linux.mak makefile.

For the lazy, I built a tarball of the .jnilib files for SWT 3.1.

Here are the exact steps I used to compile with fink:

. /sw/bin/init.sh   # Initialize fink paths
mkdir swtgtk
cd swtgtk
unzip ../swt-3.1-gtk-linux-x86.zip
rm *.so *.so.1
mkdir src
cd src
unzip ../src.zip
patch < ../../swt-darwin.diff
make -f make_linux.mak
mv *.jnilib ..
cd ..

Now that we have the .jnilib files and the swt.jar file for GTK+, we can run a test app. I wrote a quick little SWT snippet that can help here. Grab it and put it in the directory with swt.jar and the .jnilib files.

javac -classpath swt.jar Test.java
java -Djava.library.path=. -classpath swt.jar:. Test

And here's the result:

Screenshot

Files: