Background
Objective C is the programming language that is used for iOS development. To learn iOS development you need a Mac since you need Xcode to develop it. However, there is no such limitation for learning Objective C. So in this post I am going to show you how to compile and run Objective C programs on windows.
Installing GNUstep on Windows
GNUstep is a free development environment that is based on MinGW and MSYS. It has set of tools and compilers (including GCC) that lets you compile objective c programs on windows. To completely install GNUstep you need to install 3 setup files -
- GNUstep MSYS System
- GNUstep Core
- GNUstep Devel
You can download and install the same from http://www.gnustep.org/windows/installer.html.
The default installation of GNUstep would go to
- C:\GNUstep
You can also use ProjectCenter which is a GUI extension of GNUStep.
Hello World - Objective C
Now create a new file called helloworld.m and add following content to it -
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@"Hello World!"); [pool drain]; return 0; }
I have saved it at location -
- C:\GNUstep\home\<username>\Development\helloworld.m
Once you have saved it open the GNUstep shell. For me, it is at the following location -
- C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GNUstep
Once you have opened it navigate to the directory you have helloworld.m file. Then run following command -
gcc -o helloworld helloworld.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
This should create a helloworld.exe file in the same directory. Now run ./helloworld.exe and it should print "Hello World!". This is captured in the screenshot below -
No comments:
Post a Comment