http://fijiaaron.wordpress.com/2013/01/18/learning-objective-c-on-windows-with-gnustep-and-eclipse/
Learning Objective-C on Windows with GNUstep and Eclipse
Writing iOS or Cocoa apps does require a Mac with XCode, but you can learn Objective-C (and work on libraries and command-line apps) on Microsoft Windows.
GCC includes an Objective-C compiler. You can install GCC on Windows via Cygwin or MinGW.
You can also get the GNUStep implementation of the OpenStep libraries which includes the same core libraries as Cocoa — including Foundation which contains NSString, etc.
GNUstep includes a graphical environment GWorkspace which is a clone of the NeXT workspace manager. I haven’t gotten GWorkspace (or Backbone and alternative) to work on Windows or any other graphical apps, but you can use graphical GNUstep apps on Linux.
What this means is that the core libraries and command line apps can work on Windows — which is good for learning basic Objective-C concepts.
In order to use GNUstep on Windows install the GNUstep MSYS System — which gives you the core unix-like tools you know and love.
Next install GNUStep Core. You should be able to open a Shell window and execute commands.
Then install GNUStep Devel which will give you GCC with Objective-C and the GNUStep libraries which allow development.
Gorm is an interface builder for GNUStep which allows you to create (admittedly ugly) GNUstep user interfaces via drag and drop — but I couldn’t get it to work on Windows.
Once you have MSYS, GNUStep Core, and GNUStep Devel, launch the shell from your Windows Start menu.
Using a text editor, write a hello world app:
1
2
3
4
5
6
7
8
|
#import <Foundation/Foundation.h> int main( int argc, const char *argv[]) { NSAutoreleasePool *pool = [[ NSAutoreleasePool alloc] init]; NSLog ( @"Objective-C with GNUstep on Windows" ); return 0; } |
Voila, you’re coding in Objective-C on Windows with GCC!
You can see that your managing memory the old fashioned way. You don’t have ARC, but you can get modern features using clang which is the compiler used by XCode.
Directions for installing clang on Windows are available here:
http://solarianprogrammer.com/2012/03/21/clang-objective-c-windows/
Basically:
1. Checkout LLVM
2. Checkout clang into the llvm/tools folder
3. Edit llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp
Look for // FIXME: temporary hack: hard-coded paths. (on line 223 currently)
// FIXME: temporary hack: hard-coded paths.
AddPath("C:\\GNUstep\\include", System, true, false, false);
AddPath("C:\\GNUstep\\msys\\1.0\include", System, true, false, false);
AddPath("C:\\GNUstep\\lib\\gcc\\mingw32\\4.6.1\\include", System, true, false, false);
AddPath("C:\\GNUstep\\lib\\gcc\\mingw32\\4.6.1\\include\\c++", System, true, false, false);
AddPath("C:\\GNUstep\\GNUstep\\System\\Library\\Headers", System, true, false, false);
//AddPath("/usr/local/include", System, true, false, false);
break;
4. Compile
cd llvm && mkdir build && cd build ../configure --enable-optimized --enable-targets=host-only make && make install
An error is expected and not a problem groff: command not found
Now you can use ARC in your Objective-C on GNUstep compiled with clang:
1
2
3
4
5
6
7
8
9
10
|
// test.m #include <Foundation/Foundation.h> int main(){ @autoreleasepool { NSLog ( @"Objective-C with ARC on Windows" ); } return 0; } |
Here’s a sample GNUmakefile:
1
2
3
4
5
6
|
include $(GNUSTEP_MAKEFILES)/common.make TOOL_NAME = test test_OBJC_FILES = test.m include $(GNUSTEP_MAKEFILES)/tool.make |
Now run:
make CC=clang
Now, using a plain text editor (even Sublime Text) for writing code isn’t always fun..But you can use Eclipse.
Install the Eclipse CDT (C/C++ Development tools) and follow the directions here to set up Eclipse for using Objective-C:
http://wirecode.blogspot.com/2007/11/objective-c-and-eclipse.html
I haven’t yet gotten Objective-C to compile with Eclipse CD% yet but I’ll post more when I’ve got it working.