I’ve been curious about getting libdispatch and the blocks runtime compiling in Ubuntu for some time but naively guessed that it wouldn’t be for the faint-hearted since the only useful result yielded by Google was this thread on SO. How wrong I was!
For this exercise I pulled the iso for natty server from the ubuntu site and did a fresh install in a VirtualBox VM. The only extra I added during install was an SSH daemon so I could use the terminal on my Mac.
Libdispatch needs llvm/clang, libkqueue and the blocks runtime which are already available through apt-get in natty so let’s install them.
You’ll also need libpthread-workqueue0. I had to download the .deb packages from oneiric here but they installed without any hassle:
I compiled libdispatch itself from source. Don’t grab it from MacOSforge, download the tarball used to make the .deb package for oneiric. The installation will also need make, autoconf, autogen and libtool. Just to save yourself any hassle trying to solve missing header issues, install the build-essential package and gcc-multilib while you’re at it:
You should be set to compile libdispatch now. There should already be a configure file in the ‘libdispatch’ root folder so let’s install:
Make sure you force clang as the compiler, not gcc. The end of the install message should tell you where the libs were installed, for me it was /usr/local/lib. Ubuntu rather stupidly ignores erases the LD_LIBRARY_PATH variable if you set it through the shell, so add a file in /etc/ld.so.conf.d/* pointing to this location if you don’t have one already.
You should have Grand Central set up by now. Let’s write a hello world programme and see if it works:
And to compile:
And if all is well you should get the message printed to the screen. I haven’t tried anything computationally intensive yet and I wouldn’t be surprised if there’s a performance discrepancy between FreeBSD / OS X, since libkqueue is just a wrapper around epoll(). But hello world works, and that’s half the battle, right?