Objective-C for Windows
Solution 1:
Expanding on the two previous answers, if you just want Objective-C but not any of the Cocoa frameworks, then gcc will work on any platform. You can use it through Cygwin or get MinGW. However, if you want the Cocoa frameworks, or at least a reasonable subset of them, then GNUStep and Cocotron are your best bets.
Cocotron implements a lot of stuff that GNUStep does not, such as CoreGraphics and CoreData, though I can't vouch for how complete their implementation is on a specific framework. Their aim is to keep Cocotron up to date with the latest version of OS X so that any viable OS X program can run on Windows. Because GNUStep typically uses the latest version of gcc, they also add in support for Objective-C++ and a lot of the Objective-C 2.0 features.
I haven't tested those features with GNUStep, but if you use a sufficiently new version of gcc, you might be able to use them. I was not able to use Objective-C++ with GNUStep a few years ago. However, GNUStep does compile from just about any platform. Cocotron is a very mac-centric project. Although it is probably possible to compile it on other platforms, it comes XCode project files, not makefiles, so you can only compile its frameworks out of the box on OS X. It also comes with instructions on compiling Windows apps on XCode, but not any other platform. Basically, it's probably possible to set up a Windows development environment for Cocotron, but it's not as easy as setting one up for GNUStep, and you'll be on your own, so GNUStep is definitely the way to go if you're developing on Windows as opposed to just for Windows.
For what it's worth, Cocotron is licensed under the MIT license, and GNUStep is licensed under the LGPL.
Solution 2:
You can use Objective C inside the Windows environment. If you follow these steps, it should be working just fine:
- Visit the GNUstep website and download
GNUstep MSYS Subsystem
(MSYS for GNUstep),GNUstep Core
(Libraries for GNUstep), andGNUstep Devel
- After downloading these files, install in that order, or you will have problems with configuration
- Navigate to
C:\GNUstep\GNUstep\System\Library\Headers\Foundation
1 and ensure thatFoundation.h
exists - Open up a command prompt and run
gcc -v
to check thatGNUstep MSYS
is correctly installed (if you get a file not found error, ensure that thebin
folder ofGNUstep MSYS
is in yourPATH
) -
Use this simple "Hello World" program to test GNUstep's functionality:
#include <Foundation/Foundation.h> int main(void) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello World!."); [pool drain]; return; }
-
Go back to the command prompt and
cd
to where you saved the "Hello World" program and then compile it:2gcc -o helloworld.exe <HELLOWORLD>.m -I /GNUstep/GNUstep/System/Library/Headers -L /GNUstep/GNUstep/System/Library/Libraries -std=c99 -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
Finally, from the command prompt, type
helloworld
to run it
All the best, and have fun with Objective-C!
NOTES:
- I used the default install path - adjust your command line accordingly
- Ensure the folder path of yours is similar to mine, otherwise you will get an error
Solution 3:
Also:
The Cocotron is an open source project which aims to implement a cross-platform Objective-C API similar to that described by Apple Inc.'s Cocoa documentation. This includes the AppKit, Foundation, Objective-C runtime and support APIs such as CoreGraphics and CoreFoundation.
http://www.cocotron.org/