Objective-C is an OOP language often used on the Macintosh, including the Cocoa API of Mac OS X. And, since 2007, Obj-C is used for developing iOS devices applications.
However, to learn and develop in Objective-C, you are not obliged to procure a Macintosh. Actually, there is a free implementation of OpenStep framework (developed by Apple) called GNUstep, which is, multiplatform and works under GNU/Linux as well as Microsoft Windows.
In this tutorial I will guide you through the necessar steps, to ensure you get your own Objective-C code on Windows to work.
- Download and install the environment
Go to the GNUstep project official website, under the Download section, download the complete environment for compiling and running GNUstep.
PS : Download the packages and install them in order. GNUstep MSYS System first, GNUstep core second, GNUstep Devel and finally Cairo Backend.
Thus, during installation, be sure to keep the default settings. For example, the setup wizard would implicitly place the files in C: GNUstep
2. Your first script.. Hello World
Create a directory in a location of your choice to put in your project. As for me, I put all under D: in a directory called MyProject.
- Notepad++ .. My lovely editor
On Windows, the best software tool, in my opinion, to code in Objective-C.
Download it here, never mind, you will never regret it ;]
Let’s go back to our project directory. You will create two files in there, the first file will be used to compile the project and to generate the executable, and the other will contain our first Hello World program test.
Let’s go, open up Notepad++ and create the first file, call it GNUmakefile and put in the following code:
# # This script was developed for SweetTutos Tutorials # www.sweettutos.com # include $(GNUSTEP_MAKEFILES)/common.make # make a simple program in Objective-C, call it SweetTutos TOOL_NAME = SweetTutos # The implementation Objective-C file which is going to be compiled SweetTutos_OBJC_FILES = main.m # Header files of your project #SweetTutos_HEADER_FILES = xxx.h //here goes all header files (.h). For the moment, on n'en a pas. # Define compilation flags ADDITIONAL_CPPFLAGS = -Wall -Wno-import # Include rules for creating a command line tool for Objective-C include $(GNUSTEP_MAKEFILES)/tool.make
PS : Be sure to save the file with the extension (*. Mak) or just choose All types (*. *).
Now for the second file, call it main, since it is the main file of your project, then put in this code:
// //********SweetTutos*************** //****www.sweettutos.com******* // #importint main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog(@"***Sweet tutos***"); NSLog(@"***Hello World!***");//This will output Hello World! [pool release]; return 0; }
Save it with the name main.m (. M is the extension of the implementation files for Objective-C). But before, make sure you pick Objective-C from the language menu as shown below:
The work is almost finished, it remains to execute our project 😉
Open up your console (Shell) provided by the GNUstep environment, Start Menu-> GNUstep-> Shell.
For those who are already familiar with Linux, they should not get lost 😉
Enter the path to your project directory, mine was: D :/ MyProject, therefore, in the command line, it is :
cd D:/ MyProject
So far so good, you now pointing in your project directory, now type the command make to compile.
If everything goes fine, you should see the progress of the compilation as shown below:
Thus, if you return to your project directory, you should see a new folder obj which has just been added. Obj folder contains the executable of your application.
To launch the application, move to obj folder.
Under Shell, type:
cd obj
Then type:
SweetTutos
SweetTutos, remember, is the name we just choose for the executable, you can view it in the GNUmakefile file.
And here it is, Hello World is displayed on the console :]
You are on the right track. Now, you can safely code in Objective-C 😉
Don’t hesitate to leave a comment. I’d love to hear your thoughts!
Discover more from SweetTutos
Subscribe to get the latest posts sent to your email.