Compiling Cocotron Foundation Framework for Ubuntu 12.04

February 20th, 2013 · 2 Comments · Objective-C, Tutorials

This article is an updated step by step guide on how to compile the Cocotron toolchain and Foundation framework for Ubuntu 12.04 (32 bit). Most instructions from the old article for Ubuntu 11 are still valid, however, there are a couple of changes, both for the Cocotron Developer Tools (CDT) and for the files needed from the Linux system to create a functional platform interface.

Things You Will Need

  • A Mac with the latest Xcode and developer tools installed; you will use this for cross compilation. I used Xcode 4.6 on OS X 10.8.2 to test the steps described in this article. Older versions of Xcode (4.x) and/or OS X (10.6+) should also work.
  • A machine with the target Linux system installed. We will use Ubuntu 12.04 32 bit here. Installing Ubuntu as a guest OS in a VM is fine. I suggest using VirtualBox.
  • The Cocotron source code (get it by typing “$ hg clone http://cocotron.googlecode.com/hg/ cocotron” on the terminal)

Note: the Cocotron Developer Tools are now included in the Cocotron source. There is no need to download them separately anymore.

Step 1: Create a Platform Interface for Cocotron Developer Tools

The CDT require some files from your target platform. We are going to get these in this step. Don’t worry, this is already the most complicated part of the story.

Note: As of Xcode 4.3, the /Developer folder is no longer used by the Apple toolchain. Cocotron still uses the root Developer folder, so you may need to create it manually.

  1. Create directory structure /Developer/Cocotron/1.0/PlatformInterfaces.
  2. In the PlatformInterfaces directory, create a subdirectory named i386-ubuntu-linux.
  3. From your Ubuntu machine, copy the /usr/include directory to /Developer/Cocotron/1.0/PlatformInterfaces/i386-ubuntu-linux/include on your Mac.
  4. Additionally, from your Ubuntu machine, copy the /usr/src/linux-headers-x.x.xx-x/arch/x86/include/asm diectory to /Developer/Cocotron/1.0/PlatformInterfaces/i386-ubuntu-linux/include/asm on your Mac.
  5. Then copy /usr/src/linux-headers-x.x.xx-x/include/linux/compiler.h from the Ubuntu machine to /Developer/Cocotron/1.0/PlatformInterfaces/i386-ubuntu-linux/include/linux on your Mac.
  6. On your Mac, move all files and directories inside /Developer/Cocotron/1.0/PlatformInterfaces/i386-ubuntu-linux/include/i386-linux-gnu folder to the parent folder omitting the asm directory.
  7. In the i386-ubuntu-linux directory, create a subdirectory named lib.
  8. From your Ubuntu Linux machine, copy the following files to that directory from /usr/lib/i386-linux-gnu:

    crt1.o
    crti.o
    crtn.o
    libc.a
    libc.so
    libc_nonshared.a
    libm.a
    libpthread_nonshared.a
    libpthread.a
    libpthread.so

    Edit: it’s important to not copy libdl.a here (see the issue discussed in this thread.)

  9. Additionally, copy the following files to lib from your Ubuntu’s /lib/i386-linux-gnu directory:

    libdl-2.15.so
    libm-2.15.so
    libc-2.15.so
    ld-2.15.so
    libpthread-2.15.so

  10. Create symlinks:

    libdl.so.2 -> libdl-2.15.so
    libdl.so -> libdl.so.2
    libm.so.6 -> libm-2.15.so
    libc.so.6 -> libc-2.15.so
    ld-linux.so.2 -> ld-2.15.so
    libpthread.so.0 -> libpthread-2.15.so

  11. Finally, edit libc.so and libpthread.so using a text editor and replace /usr/lib/i386-linux-gnu and /lib/i386-linux-gnu paths with /Developer/Cocotron/1.0/PlatformInterfaces/i386-ubuntu-linux/lib.

Step 2: Checkout the Cocotron Source

Open up a terminal session and change the working directory to the target directory which you want to contain the cocotron source folder. Then type:

$ hg clone http://cocotron.googlecode.com/hg/ cocotron

Step 3: Build and Install Cocotron Developer Tools

  1. Switch to the InstallCDT folder by typing:
    $ cd cocotron/InstallCDT
  2. Install the Cocotron Developer Tools for Linux by typing:
    $ sudo ./install.sh Linux i386

The script will build the Cocotron toolchain for Ubuntu Linux and install all required files to allow for cross compiling using Xcode.

Step 4: Compile the Cocotron Foundation.framework

Open Xcode and load Foundation.xcodeproj from the cocotron/Foundation folder. Choose ‘Foundation-Linux-i386′ as active scheme. Build the Cocotron Foundation framework by hitting Cmd+B. If you see ‘Build succeeded’, congratulations, you have taken the first step towards Objective-C on Linux.

You may continue by reading the second part of this tutorial: Creating an Objective-C based CLI for Ubuntu 12 using Cocotron.

Tags: ···

2 responses so far ↓

Leave a Comment

Before you comment: please be kind and save me some time by NOT posting inappropriate content. Example: if you're religious that's fine. But it doesn't belong here! Comments should generally be related to the topic of the article. Thanks!

© 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.