Thursday, June 9, 2011

Objective-c on windows

Objective-c is a nicely designed language with a rich feature set, If you are aware of the recent history of programming, you will know that when steve jobs was booted out of Apple he founded NeXT, a company which created the NeXT workstations. He licensed objective-c from "StepStone" the original creators of the language.

Due to its brilliant features objective-c became the prefered platform of hardcore programmers. Then Apple bought NeXT and objective-c became a part of what came to be known as Mac OSX.

Today objective-c is the language of preference if you want to develop on Mac, Although because of the premium tag associated with Mac's its out of reach for many people.

If you want to start learning objective-c as a language before jumping on to the Apple bandwagon, there is a solution.

The blessed GNU people created an open source implementation of the objective-c compiler and called it GNUstep and guess what , its available on windows.

You can download the required tools from the link given below.

http://www.gnustep.org/experience/Windows.html

Download the four tools provided from the links available on the page and install them in the suggested order.

GNUstep MSYS System -> GNUstep Core ->GNUstep Devel -> Cairo Backend.

After the installation is done from the windows start menu open the GNUstep shell, remember its very important to get start the GNUstep shell , if you will try to program in objective-c from the dos shell it will fail.

Opening the shell opens up a bash like interface, those people familiar with the linux command line will be comfortable here, all your favourite tools like Vim , make are avialable.

Create a new directory using the command : mkdir dirName.
Go into that directory using the command : cd dirName.

now create a new source file using Vim.
vim filename.m

Notice the weird extention of the source file we just created, well thats the standard extention for the source files containing objective-c code.

In the newly created source file write the following code.

#import <Foundation/Foundation.h>
int main (int argc
, const char *argv[])
{
NSLog (@
"Hello, Objective- C!");
return (0);

}

Now to compile the code there are 3 options:

1. compile directly using gcc
2. create a standard makefile and use the provided make utilty
3. use the GNUstep make utility

In this post i am going to cover only the first option.

To compile using gcc directly just use the following command:

gcc -o output fileName.m -I/c/GNUstep/GNUstep/System/Library/Headers \

-L /c/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base \

-fconstant-string-class=NSConstantString


An executable file , output.exe will be created in the present working directory.

To execute it just write ./output.exe on the command prompt.


I will try and cover the makefile and GNU make methods of compiling as they are more practical and basically cooler to work with.


Till then enjoy the Mac goodness on your Pc.


Regards,

Ishan

No comments:

Post a Comment