Wednesday 8 June 2011

Developing Objective-C on Windows PC


As I'm using Windows PC most of the day I wanted to look into finding a way to try and learn Objective-C while on Windows PC. I just managed to compile and run my first "Hello World!" code so thought might be useful to make a note how I got there.

I thought I'll be able to find something I can plug-in to Visual Studio to be able to write and compile Objective-C but couldn't. Searching the internet I found a Mac forum where number of people asked the question - how to code Objective-C in Windows PC? The answer was short (Apple style) - Go to www.gnustep.org!

So visited GNUstep site and found GNUstep installer for Windows: www.gnustep.org/experience/Windows.html. From this page I downloaded and installed in order (as advised in the page):


GNUstep MSYS System Required 0.28.1 - MSYS/MinGW System
GNUstep Core Required 0.28.0 - GNUstep Core
GNUstep Devel Optional 1.3.0 - Developer Tools

The installation procedure created a program group in the Start/All Programs menu called GNUstep and in there I found Shell application which simulates Unix console.

I used Notepad to create a simple Objective-C file:

#import <Foundation/Foundation.h>

    int main (int argc, const char * argv[])

    {

        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSLog(@"Hello World!");

        [pool drain];

        return 0;

    }

and saved the file with ".m" extension. When I tried to compile it the first time it failed to find the file so I moved it under C:\GNUstep\msys\1.0\home\dreriMIX folder which was created by the installer.

I ran the command
gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries objC1.m -lgnustep-base -lobjc
and that created an application called a.exe which when I run (use ./a in the console) I get:

2011-06-08 11:27:14.354 a[20272] Hello World!

Success!

No comments: