Saturday, August 27, 2011

Compiling Objective C inside Linux Ubuntu 11.04 Natty Narwhal! ( Guide to Installing and working with GNUSTEP )

16 comments

         As a very Apple addicted person I always wanted to learn developing iOS and Mac apps. When I got my first iPod touch last december I started to love it's operating system called iOS. And I was amazed by the iMacs and Macbook Pros in Apple stores but I couldn't buy one yet. You know, money matters :(   Even though I don't have a Mac to do iOS developing I wanted to do those stuff so badly. Objective C is used for that and I wanted to learn it so badly. But I couldn't as I had my high school exams. But finally last night i figured it out :D So if you are a person just like me, who have endless willings to learn iOS and Mac programming without a mac this is the place :)


            Objective C is used to make iOS and Mac apps. This language is derived from C language and this is a mid level object oriented programming language which was developed by Apple Inc. Prior experience with C++ or C will be a extra advantage. But it's not necessary. Objective C is currently compiled with xCode software in Mac Os X. But don't worry you can do it as this way too....   Okay let's get to work then.

You should have installed Linux ubuntu for this. I tried this via linux Ubuntu 11.04 - Natty Narwhal. But this should work with other versions too. Please kind enough to inform me if there's any problem with older versions. Well this guide consist of two steps. 1) Installing 2) Compiling ............. Let's do this :) Remember to enter your computer password whenever terminal requies it :D




         
                          Installing GNUSTEP in Ubuntu and getting it worked :)


1) Open the terminal. And enter below commands one by one. You should have a working internet connection dude :)

2) sudo apt-get -y install build-essential

3) sudo apt-get -y install gnustep

4) sudo apt-get install gobjc

5) sudo apt-get install gnustep-make

6) sudo apt-get install libgnustep-base-dev


Okay It's done.... Now you have successfully installed GNUSTEP in your computer. Well I know it took some long time to download it as it cost about 200MB :P But be happy you can run Objective C ! :D


               
                               Compiling a simple program with GNUSTEP !

1) Open the terminal.

2) Type gedit name.m

   Info - You should use the .m extension to compile Objective C programmes. If you use .txt it will be frikkin useless. And use your desired name in the "name" field. And use it by changing everywhere hereafter in my codes.


3) After you hit ENTER key after typing last code a Gedit text editor will be opened. As "Home" directory is the default in terminal this will be saved in "Home" directory...

4) Then type this simple sample code in that text editor. And then hit the " Save " button and close it ;)

 
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Objective C is great");
[pool drain];
return 0;
}



5) Now come back to the terminal and type-     . /usr/share/GNUstep/Makefiles/GNUstep.sh

   info - You should enter this code everytime you start a new terminal window. I know this is a disadvantage. But it does the job ;)


6) gcc `gnustep-config --objc-flags` -lgnustep-base name.m -o name

   info - Change the "name" field to the name of gedit file you created at first step!


7) ./name

   info - After hitting enter button you will get a phrase in the terminal saying " Objective C is great :D "







Congratulations dude,,,, You have just made your first effort a success in Objective C :)

AND FOR LEARNING OBJECTIVE C I recommend you the book " PROGRAMMIN IN OBJECTIVE C 2.0 by Stephen G. Kochan " .. I downloaded a copy from thepiratebay.org But I don't remember the link for that torrent. If you couldn't find any book and need a one so badly, just ask me and I'll upload it. :)



Any questions??? Feel free to ask ;)

16 comments:

Post a Comment

Keep a comment if you like this.. Thank you :)