You are here

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
.

Prerequisites

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 :
apple-x86-gcc-DEBIAN.zip (97,7 Mb)

* 64-bit "amd64" version :
apple-x86-gcc-DEBIAN-AMD64.zip (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 :
./testGTK2

Well done !

Comments

great job, thanks for your hard work.

(originally posted by andytao)

This is good stuff. But I cant install the odcctools package on my Lucid 10.04 64bit machine and the other deb's require the tools. Error

dpkg: dependency problems prevent configuration of apple-x86-odcctools:
apple-x86-odcctools depends on libssl0.9.8 (>= 0.9.8m-1); however:
Version of libssl0.9.8 on system is 0.9.8k-7ubuntu8.13.
dpkg: error processing apple-x86-odcctools (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
apple-x86-odcctools

Been looking for hours cant find a solution?

(originally posted by MIlo)

Hi Milo,

Actually, you hit a (rare) case where Lucid's packages -being a little bit older than Debian Squeeze's ones- rise a problem.
A workaround is to manually download and install Squeeze's libssl0.9.8.
Once you have the .deb, install it with :
dpkg -i libssl0.9.8_0.9.8o-4squeeze14_amd64.deb

PS : should work, but I'm not responsible ;-).

Hi again. Appreciate that quick reply

Your solution worked! I had to remove the previous libssl-dev from synaptic. I managed to compile a simple script and run it on mac

Unfortunately I ran into another problem. When compiling a gtk code with

valac --pkg gtk+-2.0 testGTK.vala

it worked and I could run it on my Linux machine and I know the mac compiler also works because I cross compiled a hello world type test script which worked. Now I try to compile the mac gtk with

valac --cc=i686-apple-darwin10-gcc --pkg gtk+-2.0 -o testGTK testGTK.vala

and I get architecture errors:

ld warning: in .../gtk-macosx/lib/libgtk-quartz-2.0.dylib, file is not of required architecture
ld warning: in .../gtk-macosx/lib/libgio-2.0.dylib, file is not of required architecture
ld warning: in .../gtk-macosx/lib/libatk-1.0.dylib, file is not of required architecture
ld warning: in .../gtk-macosx/lib/libgdk-quartz-2.0.dylib, file is not of required architecture
etc...
Undefined symbols:
"_gtk_main", referenced from:
_vala_tutorial_my_app_main in cclTp22Z.o
"_gtk_init", referenced from:
_vala_tutorial_my_app_main in cclTp22Z.o
etc...
ld: symbol(s) not found
collect2: ld returned 1 exit status
error: cc exited with status 256
Compilation failed: 1 error(s), 4 warning(s)

Could it be because vala is 64bti and trying to make a 32bit mac app?

Thanks again

(originally posted by Milo)

Just an update I figured out for just normal compilation you need -m32 option. I don't know the vala equivalent

(originally posted by Milo)

Have you tried to do : valac ... --Xcc="-m32" ?

Add new comment

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.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.