How to build Cocotron

At this point you should have a working GCC patched for NEXT Objective-C runtime.

Tools required: subversion, obj-c patched gcc, make, cmake

Go and grab cocotron from subversion:

svn checkout http://cocotron.googlecode.com/svn/trunk cocotron-trunk

Building cocotron's Foundation is not as simple as GCC, so I'll be commenting all the steps.

cd cocotron-trunk/Foundation # we're building only Foundation

get the build script from this ticket: http://code.google.com/p/cocotron/issues/detail?id=168 and put it in current directory

mkdir build
cd build
cmake -DCMAKE_C_COMPILER=/opt/objc/bin/gcc \
    -DCMAKE_CXX_COMPILER=/opt/objc/bin/g++ \
    -DCMAKE_INSTALL_PREFIX=/opt/objc ..

If you have cocotron trunk r242 or below do and fix one nasty bug:

at Foundation/NSInvocation.m line 438 change

#ifndef WIN32

to

#if 0

as this bug fires on linux too.

Now you're ready to build Cocotron:

cd build
make
sudo make install

Test code

#import <Foundation/Foundation.h>

int main(int argc, char *argv[])
{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSLog(@"Hello, Objective-C World!");

        [pool drain];
        return 0;
}

Build with:

/opt/objc/bin/gcc test.m -o test -I/opt/objc/include -L/opt/objc/lib -lFoundation -lpthread -ldl

You might also be interested in adding /opt/objc/lib into your /etc/ld.so.conf and running ldconfig

Attachments