Running Objective C on Windows

Posted: April 19, 2012 in Objective C
Tags: , , ,

Objective C Programming in Windows using GNUStep

GNUStep is a free, object oriented development environment with built in tools such as a compiler. The C/C++ compiler included (gcc) also supports compiling Objective C programs. It also has a graphical development kit with API similar to Cocoa framework (since both of them were derived from the old OpenStep framework). So installing GNUStep on Windows gives an instant development environment for Objective C programs. An extension to GNUStep is the ProjectCenter (Xcode equivalent) using which graphical programs can be built.

Installing GNUStep on Windows

GNUStep is available as a Windows installer from the official page.  I recommend downloading and installing GNUStep System, GNUStep Core and GNUStep Devel. Note that the latest version available as of October 2009 is 0.23.0 and this version is not compatible with ProjectCenter 0.50.  If you are planning to use ProjectCenter I recommend that you download 0.22.0 version of GNUStep from the download page. Here is a summary of what is required,

  • Objective C programming only – GNUStep 0.23 (System | Core | Devel)
  • Objective C Programming and ProjectCenter 0.50 –  GNUStep 0.22 (System | Core | Devel)

You can download pre-compiled version of ProjectCenter 0.50 for Windows from here.

Once you install all the binaries above, you will have GNUStep shell under Programs->GNUStep (See figure).

Click on the Shell to invoke the command line interface. This shell is based on MinGW (collection of gcc compiler and command line tools) and using it you can compile and run Objective C programs. The command line is similar to Unix/Linux command line and you can navigate to any folder in your windows machine. Using the built in gcc program you can compile and run Objective C programs.

Compiling and running Objective C programs in GNUStep on Windows

Create the following program and save it with the name helloworld.m using notepad,

#import <Foundation/Foundation.h> 
int main (int argc, const char * argv[])
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  NSLog (@"Hello World!");
  [pool drain];
  return 0;

Now using GNStep shell navigate to the folder where helloworld.m is stored (in my case it is cd w:/prg). Type in the following command to compile helloworld.m.

gcc -o helloworld helloworld.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString

Common Errors during Objective C compilation

  • error: cannot find interface declaration for `NXConstantString’ – This means that you haven’t added the switch -fconstant-string-class=NSConstantString to the gcc command line.
  • Foundation/Foundation.h: No such file or directory – This means that gcc is unable to find Foundation header classes. Use the switches -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries
  • stray ‘@’ in program – This means that you have the wrong double quote in your source code. Use instead of .

Now you are all set for Objective C programming and a bit of Cocoa programming on Windows. Good luck! and buy a Mac machine when you are ready to write iPhone programs.

for more info click here

For more updates and such new code tricks visit


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s