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.
- Create directory structure /Developer/Cocotron/1.0/PlatformInterfaces.
- In the PlatformInterfaces directory, create a subdirectory named i386-ubuntu-linux.
- From your Ubuntu machine, copy the /usr/include directory to /Developer/Cocotron/1.0/PlatformInterfaces/i386-ubuntu-linux/include on your Mac.
- 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.
- 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.
- 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.
- In the i386-ubuntu-linux directory, create a subdirectory named lib.
- From your Ubuntu Linux machine, copy the following files to that directory from /usr/lib/i386-linux-gnu:
Edit: it’s important to not copy libdl.a here (see the issue discussed in this thread.)
- Additionally, copy the following files to lib from your Ubuntu’s /lib/i386-linux-gnu directory:
- 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
- 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
- Switch to the InstallCDT folder by typing:
$ cd cocotron/InstallCDT
- 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.