Sunday, 29 April 2018

Objective C programming in Windows with GNUStep

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 -

  1. GNUstep MSYS System
  2. GNUstep Core
  3. GNUstep Devel
 You can download and install the same from http://www.gnustep.org/windows/installer.html.

Installation : For the full environment for compiling and running GNUstep. Install the following packages in order. First install the gnustep-msys-system package, which contains all the packages required to run GNUstep (shell, graphics libraries, etc). Then install gnustep-core, which contains the core GNUstep libraries. If you want to compile and develop your own GNUstep applications, also install the gnustep-devel package.

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 -







Related Links

t> UA-39527780-1 back to top