You are here

Add new comment

Tutorial : cross-compile from Linux to Mac OS X (Vala)

Objectives : compile a Vala/GTK+ application under Linux, and produce a valid Mac OS X binary.

We have a Vala application using GTK+2 as its graphical toolkit :

We want to create a Mac OS X version of it, without modifiying the source code nor installing Mac development tools.

PS 1 : GTK+3 isn't supported on Mac OS X at this very moment.
PS 2 : compiling directly on Mac OS X is feasible, but requires additional software


A Linux Debian or Ubuntu distro, with Vala installed.

To install Vala, please read this previous article, part 1).

1) Install the compilation toolchain

- Download the GCC compiler for Mac OS X under Linux :

* 32-bit "i386" version : (97,7 Mb)

* 64-bit "amd64" version : (100 Mb)

(ps : Extract the ZIP file and type :
apt-get install libssl0.9.8
dpkg -i apple-x86-odcctools_758.159-0flosoft11_i386.deb
dpkg -i apple-uni-sdk-10.5_20110407-0.flosoft1_i386.deb
dpkg -i apple-x86-gcc_4.2.1~5646.1flosoft2_i386.deb

- Download GTK+ 2.24.9 for Mac OS X under Linux :
gtk2249-MACOSX_(TARNYKO).tar.bz2 (8,69 Mb)

(ps : Move the file wherever you want and extract it by :
tar xfvj gtk2249-MACOSX_(TARNYKO).tar.bz2)

- Adapt GTK+ to its location :
In a terminal, move to the "gtk-macosx" folder you have just extracted. If you extracted it to "/opt/gtk-macosx" e.g. :
cd /opt/gtk-macox
then do :
find -name '*.pc' | while read pc; do sed -e "s@^prefix=.*@prefix=$PWD@" -i "$pc"; done

2) Compile

- We will tell "pkg-config" to locate GTK+ libraries in our custom path. If you extracted to "/opt/gtk-macosx" e.g. :
export PKG_CONFIG_PATH=/opt/gtk-macosx/lib/pkgconfig

We are ready ! We will use this simple source code as an example.

- Compile the example :
valac --cc=i686-apple-darwin10-gcc --pkg gtk+-2.0 -o testGTK2 testGTK2.vala

A new testGTK2 executable should have been created if everything went well.
It won't run on our Linux system, because it's suited for Mac OS X !

3) Release

- Create a folder containing the binary and the Mac OS X libraries (.dylib). If you extracted to "/opt/gtk-macosx" e.g. :
mkdir ~/distri
cp testGTK2 ~/distri
cp /opt/gtk-macosx/lib/*.dylib ~/distri

- Here we go ! Transfer this folder to a Mac. Open the Terminal app, move inside the folder and run the binary :

Well done !

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.