Compiling Objective-C on Windows via Command Line

I’ve been tinkering with Objective-C for a few weeks on my Mac laptop. I wanted to find out if it is possible to compile on Windows for when I don’t have access to a Mac. I just wanted to be able to write basic Console type programs, but have access to the basic Cocoa objects. As this was non-trivial, and some of the software is not particularly mainstream, I am documenting here how I went about doing this.

Firstly install cygwin.

Next, install GCC via the cygwin setup package. GCC supports compiling Objective-C out of the box, but we need an implementation of the Cocoa libraries to give us access to objects such as NSObject, NSArray etc.

We get this by installing the GNUStep libraries. You need both the Core and System packages, currently as version 0.23.0/1

To compile an Objective-C program into an executable, we run the following two commands :

gcc -c program.m file1.m -I c:/GNUStep/GNUStep/System/Library/Headers -L c:/GNUStep/GNUStep/System/Library/Libraries -fconstant-string-class=NSConstantString -enable-auto-import

gcc -o test.exe program.o file1.o -lobjc -lgnustep-base -enable-auto-import -I c:/GNUStep/GNUStep/System/Library/Headers -L c:/GNUStep/GNUStep/System/Library/Libraries

Hope that helps someone.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
This entry was posted in Uncategorized and tagged . Bookmark the permalink.