Learn Objective-C on Windows
Posted on September 14, 2011 by Sol

This post is for the ones that want to start learning Objective-C but, for various reasons, must work in a Windows environment only. Maybe you don't have the money to buy a new Mac computer or maybe you are not allowed to use a non-Windows machine at your "working" place :).

The solution I will present you here is not a replacement for a real Mac computer, but rather a temporary solution that will let you learn the basis of Objective-C on a Windows based machine. I will show you how to install an Objective-C environment (the compiler and a Unix like shell) and how to compile a simple Hello World program.

Let's start by installing GNUstep which aims to be "a free and open version of the Cocoa (formerly known as NeXTSTEP/OpenStep) APIs and tools". For more information read the introduction from http://www.gnustep.org/information/aboutGNUstep.html .

Go to http://www.gnustep.org/experience/Windows.html#state and download the stable versions of GNUstep MSYS System, GNUstep Core and GNUstep Devel and install them in the same order.

Start the GNUstep command prompt (shell in the Unix terminology) from Start ... All Programs ... GNUstep ...Shell. You should see a Dos like window in which you can type commands. Be aware that a Unix like shell is more powerful than a typical Windows command prompt; if you want to make your life easier you will need a good shell tutorial.

Open your favorite text editor (this is not Word or Notepad), if you don't have one you could use Programmer's Notepad from http://www.pnotepad.org/ or Notepad++ from http://notepad-plus-plus.org/ , both are equally powerful and have syntax highlighting for Objective-C.

Using one of the above editors write or paste these piece of code:

1
2
3
4
5
6
#import <Foundation/Foundation.h>;

int main () {
    NSLog (@"Hello World!");
    return(0);
}

Save your code in the home folder of your GNUstep installation, this should be something like C:\GNUstep\home\User_Name. Your program should have a name that ends with dot m, for example Hello.m in order to be recognized as an Objective-C file by the compiler.

Now, let's compile the above code, write this line in the GNUstep shell window:

1
gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries Hello.m -lgnustep-base –lobjc –o Hello.exe

You should have (if everything works well) a new executable Hello.exe file next to your Hello.m program. Check the resulted exe with:

1
./Hello.exe

in your shell window:

All you have to do now is to start learning Objectve-C on your Windows machine!

If you want to learn more about Objective-C I could recommend you two books: Programming in Objective-C by Stephen G. Kochan and Objective-C Programming by Aaron Hillegass.

blog comments powered by Disqus