Friday, January 21, 2011

Learn Objective-C on Windows

In todays world there are loads of Operating systems exists, among them Mac OS easily one of the most eye candy and lovely OS most people want to use but for some reasons most people doesn’t own a Mac. As programmers we all love to program for iPhone I don’t know why but people love to. so how can they develop applications for iPhones basically in Objective-C without an Apple Mac. the simple answer is Hackintosh but there are lot of other alternatives as well I will explain few of them in a later post but today I am going to explain how to learn Objective-C on a Windows machine. recently I installed Mac OS X on my machine but still I use Windows and Linux most of the time. So if there is way for you to at least learn objective-C on Windows that would be really helpful.
in order to compile Objective-C on Windows we need to install following package which is called GNUstep if you are a Windows user go to this link and download and install at least the first three packages.Capture3
then go to start –> all programs –> GNUstep –> shell
it is a Unix like terminal where you can issue some unix terminal commands. Then open your favorite text editor in my case I am using Vim by just typing vim and enter on the shell I opened up earlier but you can use Notepad++ or any other appropriate text editor.
#import <stdio.h>

int main( int argc, const char *argv[] ) {
printf( "hello world\n" );
return 0;
}

Capture4
and save it as hello.m remember to save it in the home folder as GNUstep installed if you’d have used vim there won’t be any problem but if you used any other text editor don’t forget to save it in there in my case the path is : C:\GNUstep\home\Keshan so yours might look similar to this. Then in the terminal type :

gcc `gnustep-config –objc-flags` –L /GNUstep/System/Library/Libraries hello.m –lgnustep-base –lobjc

Capture1
and then to run simply type ./a

Capture2
so this is a basic hello world program but Objective-C is bit different this is simply a C like program actually Objective-C is an extended version of C you can find loads of tutorial about Objective-C and try them out on Windows with this cool package. here is the same code run on Mac OS X

Capture5