Objective-C on Linux: Setting up GNUstep, clang (llvm), Objective-C 2.0, Blocks Runtime, GCD on Ubuntu 12.04

February 24th, 2013 · 23 Comments · Objective-C, Tutorials

I recently posted a couple of articles about how to use Cocotron for cross compiling Objective-C applications for Linux. In my opinion, what makes Cocotron great is that you can continue to work on the OS X platform and harness the conveniences of code editing with Xcode. However, there are a number of drawbacks that I did not yet manage to overcome. The main issue I have with Cocotron is that it’s still based on GCC and hence does not provide support for some nice modern features of Objective-C, most notably blocks and Grand Central Dispatch (GCD) (both require clang.) What is more, Cocotron doesn’t come with GUI support on Linux (only Windows is supported as of now.)

GNUstep appears to be a good alternative if you are willing to sacrifice the ability to work with an Xcode project, but is it feasible to set it up on Ubuntu with support for clang, blocks and GCD?

Turns out it is.

As information about this particular setup appears to be a bit scattered over the web, and there happens to be no defacto step-by-step guide on how to accomplish this easily, I decided to try and fill this gap.

So no more babbling, let’s just jump right in!

Things You Will Need

  • Ubuntu 12.04 (Desktop) installed on a (virtual) machine.
  • That’s it, really!
If you don’t want to carry out the steps listed below manually, I have prepared a shell script, which should do all the work for you.

Step 1: Get a Bunch of Packages

Open up a terminal session and enter the following command:

sudo apt-get install build-essential clang libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev gobjc libxml2-dev libjpeg-dev libtiff-dev libpng12-dev libcups2-dev libfreetype6-dev libcairo2-dev libxt-dev libgl1-mesa-dev

Note: I am assuming that you start with a fresh Ubuntu instance, so I am listing all required packages to start from there. If you had libdispatch-dev installed previously, please remove it before proceeding with step 2. (It causes trouble when configuring GNUstep base.) We will re-install it later again.

Step 2: Download GNUstep and libobj2 Sources from the GNUstep Website

It’s important NOT to install the respective Ubuntu packages (gnustep-devel, libobjc2). Instead, download the following from the GNUstep resources site:

  1. GNUstep Make
  2. GNUstep Base
  3. GNUstep GUI
  4. GNUstep Backend

Additionally, get the latest libobjc2 sources from http://download.gna.org/gnustep/.

Finally, move the files into an install folder, and unpack them there. (I named mine ‘gnustep-dev’ and put it into my home directory.)

Step 3: Install libobjc2

Change into the unpacked libobjc2 directory and then type the following on your terminal:

export CC=clang
sudo make install

Note: It’s important to complete the following steps within this terminal session. Otherwise, you need to repeat export CC=clang (set the C compiler to clang instead of gcc) if you continue with a fresh session.

Step 4: Install the GNUstep Tools and Libraries

  1. Install GNUstep Make by changing into the unpacked gnustep-make-x.x.x directory and typing:
    sudo make install
  2. Install GNUstep Base by changing into the unpacked gnustep-base-x.x.x directory and typing:
    sudo make install
  3. Install GNUstep GUI by changing into the unpacked gnustep-gui-x.x.x directory and typing:
    sudo make install
  4. Install GNUstep Backend by changing into the unpacked gnustep-back-x.x.x directory and typing:
    sudo make install

Step 5: Install libdispatch-dev

On the terminal, type:

sudo apt-get install libdispatch-dev

Step 6: Try it out

I have set up a simple test program and named it main.m:

Just download it to your Ubuntu machine.

On the terminal, go into the directory containing main.m and execute the following command to compile the source file:

clang `gnustep-config --objc-flags` -o main -x objective-c main.m -fconstant-string-class=NSConstantString -fobjc-nonfragile-abi -fblocks -lgnustep-base -lgnustep-gui -ldispatch -I/usr/include/GNUstep -L/usr/lib/GNUstep

Finally, execute the built binary by typing:


If everything works correctly, you should see the following terminal output:

2013-02-24 01:08:20.981 main[6710] 21
Hello, world from a dispatch queue!

Additionally, an alert panel should pop up as seen in the screenshot above.


Tags: ··

23 responses so far ↓

  • 1 Creating an Objective-C based CLI for Ubuntu 12 using Cocotron  Feb 24, 2013 at 2:51 am

    […] Compiling Cocotron Foundation Framework for Ubuntu 12.04 Objective-C on Linux: Setting up GNUstep, clang (llvm), Objective-C 2.0, Blocks Runtime, GCD on Ubun… […]

  • 2 vasilis  Feb 25, 2013 at 5:29 pm

    Hi there,
    Awesome and (very) rare material !
    Though I’m getting an error while making the gnu-base (Ubuntu 12.04 32):

    Creating GSspell.service/Resources…
    Creating GSspell.service/Resources/Info-gnustep.plist…
    ././obj/make_services: error while loading shared libraries: libgnustep-base.so.1.24: cannot open shared object file: No such file or directory
    make[3]: *** [GSspell.service/Resources/Info-gnustep.plist] Error 1
    make[2]: *** [GSspell.all.service.variables] Error 2
    make[1]: *** [internal-all] Error 2
    make: *** [internal-all] Error 2

    Any ideas?

  • 3 vasilis  Feb 25, 2013 at 5:31 pm

    … I meant the gnu-gui of course …

  • 4 Tobias  Feb 25, 2013 at 6:45 pm

    Strange and interesting.

    Did you run the script or did you follow the steps manually?

    Please make sure that libgnustep-base.so.1.24 has been installed correctly. It should be in your /usr/local/lib folder.

    If that doesn’t help, try the following when compiling GNUstep GUI:
    export LD_LIBRARY_PATH=’/usr/local/lib’

    Hope this helps! If not, please send me the config.log file from the gnustep-gui build directory via mail.


  • 5 gspanos  Mar 11, 2013 at 12:31 am

    I had the same problem as @vasillis. export LD_LIBRARY_PATH=’/usr/local/lib’ is NOT enough. You must do:
    echo “export LD_LIBRARY_PATH=’/usr/local/lib’” >> ~/.bashrc

    Then logout and login on the terminal and everything should work fine.

  • 6 Tobias  Mar 11, 2013 at 8:49 am

    I was thinking that at least one of the packages from step 1 should add /usr/local/lib to ld.so.conf.d.

    If that’s not the case, a better way to add it permanently and for all users is creating a conf file in /etc/ld.so.conf.d as described here: http://stackoverflow.com/questions/9151491.

  • 7 vasilis  Mar 11, 2013 at 1:50 pm

    Hi Tobias,
    Just got it to work by following @gspanos’ suggestion plus the flags from this SO post -> http://stackoverflow.com/questions/13446450/simple-hello-world-in-objective-c-with-clang-and-gnustep-does-not-compile

    Thanks again for all the info 🙂

  • 8 Tobias  Mar 11, 2013 at 4:24 pm

    Can you verify that the clang command from this blog post works for you if you have /usr/local/lib in a config file in your /etc/ld.so.conf.d directory?

    I would really like to know whether and why the instructions in this article may diverge from what I figured out on my bare Ubuntu 12.04 system.


  • 9 nicerobot  May 26, 2013 at 6:40 pm

    Nice. I wrote [a Gist](https://gist.github.com/nicerobot/5652802) to automate all this. It works for me in Ubuntu 12.10.

  • 10 jimbas  Jun 11, 2013 at 3:44 am

    Hi Tobias

    Thanks you very much. Just that I got trouble when compiling gnustep-gui, but I have solved already. It works now.

    When compiling gnustep-base, after execute sudo make install, I execute ‘sudo ldconfig’. gnustep-gui make & make install success, then I execute ‘sudo ldconfig’ again. then make gnustep-back success as well

  • 11 Schr3da  Jun 16, 2013 at 6:30 pm

    Thank you so much worked great !!! Just used the change from nicerobot…

    curl -ks https://gist.github.com/nicerobot/5652802/raw/install.sh | bash –

  • 12 Schr3da  Jun 16, 2013 at 6:31 pm

    Thanks also for the great tutorial THIS IS REALLY RARE FOR OBJECTIVE C

  • 13 Schr3da  Jul 5, 2013 at 11:52 pm


  • 14 Jeffrey Thompson  Jul 20, 2013 at 5:25 pm

    Thank you for the informative write-up of compiling GNUstep with clang & libobjc2. I used all of the latest systems:
    * Ubuntu 13.04
    * GNUstep Base 1.24.4
    * GNUstep GUI 0.23.1
    * libobjc2 1.7

    You install libobjc2-1.7 a little differently:

    mkdir Build
    cd Build
    cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
    make && sudo -E make install

    And then I had to tweak the compiling command for your example a little bit (I just used the defaults for all of the make installs; I added -lobjc and -L to find the GNUstep and objc library):

    clang `gnustep-config –objc-flags` -o main -x objective-c main.m -fconstant-string-class=NSConstantString -fobjc-nonfragile-abi -fblocks -lgnustep-base -lgnustep-gui -ldispatch -lobjc -I/usr/local/include/GNUstep -L/usr/local/lib/GNUstep -L/usr/local/lib

    Also I use Feedly service to track blogs and for some reason your blog doesn’t work with Feedly (FYI).

  • 15 Objective C till Linux | Arkeoblog  Sep 3, 2013 at 7:45 am

    […] har testat att installera libobjc2 + clang via pakethanteraren både på gentoo och ubuntu, men det fungerar inte på någon av distributionerna! Istället får man kompilera det själv […]

  • 16 Objective C on Ubuntu 12.04 With Blocks and ARC | feloneouscat  Oct 25, 2013 at 11:09 pm

    […] first misstep was using the instructions here – which aren’t bad, but when you try to get things working in an IDE (I use Codelite just […]

  • 17 Good article about setting up objective-c development environment on Ubuntu | Johnny Ma  Jan 23, 2014 at 9:21 pm

    […] http://blog.tlensing.org/2013/02/24/objective-c-on-linux-setting-up-gnustep-clang-llvm-objective-c-2… […]

  • 18 Imran Ahmad  Mar 21, 2014 at 5:55 am

    While installing Install GNUstep Base by changing into the unpacked gnustep-base-x.x.x directory and typing:

    sudo make install

    Following Error occurred..

    NSException.m:813:3: error: use of undeclared identifier ‘_objc_unexpected_exception’
    _objc_unexpected_exception = callUncaughtHandler;
    1 error generated.
    make[4]: *** [obj/libgnustep-base.obj/NSException.m.o] Error 1
    make[3]: *** [internal-library-all_] Error 2
    make[2]: *** [libgnustep-base.all.library.variables] Error 2
    make[1]: *** [internal-all] Error 2
    make: *** [internal-all] Error 2

  • 19 TNTftw21  Apr 5, 2014 at 12:28 am

    I am having a problem with the script to install gnustep. First, I had to replace apt-get with yum, which, of course, yum couldn’t find most of the packages. Now, I have gnustep installed, but it keeps saying upon compilation that “Foundation/Foundation.h cannot be found.” Does this have something to do with yum not being able to get the packages?

  • 20 Galen Rhodes  May 14, 2014 at 8:22 pm

    I followed all of the directions and got a successful build, but when I run the test app I get a Segmentation Fault.

    Has anyone else seen this?

  • 21 Galen Rhodes  May 15, 2014 at 2:25 pm

    An update: I tried this both on 64-bit Ubuntu 12 and on 32-bit Raspian (Linux running on a Raspberry Pi SoC (http://www.raspberrypi.org)) and got the same result. Here are the versions I worked with:

    clang 3.0 & 3.3

    On both machines the compiled test program threw a Segmentation Fault.

    Any ideas?

  • 22 Jake  Jun 13, 2014 at 3:02 pm


    I think I installed the same versions of the gnustep tools you did, and I also got the seg fault.

    Using the extra compiler flags -O0 -g and running ‘main’ with gdb, I could tell it was related to the use of @autoreleasepool, but I don’t know enough about Obj-C to understand what the stack trace was telling me.

    At any rate, I commented the @autoreleasepool block (i.e., the opening and closing brackets only) and recompiled with success. Not sure if I did this at the expense of a memory leak.


  • 23 david  Dec 10, 2014 at 5:52 pm

    on ubuntu 14.04, I have an error during the “gnustep-base/ make” :

    Compiling file GSXML.m …
    GSXML.m:987:38: error: incomplete definition of type ‘struct _xmlBuf’
    string = UTF8StrLen(buf->buffer->content, buf->buffer->use);
    /usr/include/libxml2/libxml/tree.h:104:16: note: forward declaration of ‘struct _xmlBuf’
    typedef struct _xmlBuf xmlBuf;

    I tried to install an older version of libxml2 (2.7.8), but still an error…

    help please…

© 2013 Tobis Lensing. All rights reserved. Powered by Wordpress — based upon Cutline by Chris Pearson. This page reflects the personal opinion of the author and is in no way linked to institutions the author is working or has worked for. For more information, see the disclaimer and Privacy Policy.