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!
Hi
I am getting the error sh: SweetTutos: command not found
great tutorial. But right at the end you need to type ./SweetTutos
(that is dot forwardslash before the executable filename)
many thanks
you said “PS : Be sure to save the file with the extension (*. Mak)”
this confused me and calling it GNUmakefile.mak does not work. It must not have an extension *.mak on the end of the file or make will not accept it.
“No target specified and no make file found” error! what should I do?
Awesome stuff but I get some error: *No targets specified and no make file found”
Hey guys, I found the solution for “No target specified and no make file found” error.
Please just save those “make file” without extention, just name it “GNUmakefile” (without extension)
this post already for a while.
need to be fixed by follow:
1.save your makefile with named ‘GNUMakefile’ without extension
2.build with command ‘make -f GNUMakefile’
wait…. what?
I’m getting the same error (sh: SweetTutos: command not found)
where am I putting this “./SweetTutos”?
thank u so much.. it would be really difficult to compile without your help.. thanks a ton…!!
how do I open the shell on windows 8??
it says no such file or directory
I don’t understand… this article starts off explaining how to install Objective-C under Windows, and then later switches to Linux when showing how to compile and run the program.
Can you please explain how to compile and run under Windows, assuming the standard installation into the default folders? I followed all the download and installation instructions just fine, and even created the test files GNUmakefile and main.m. But from then on, it jumps to Linux.
Thanks.
OHHHH, I am such a doofus!! I thought you were showing an example in Linux. I missed the step to open the newly installed Windows program called /GNUstep/Shell on the Windows Start menu! Yup, when you click THAT, the examples make much more sense. Thanks!
Awesome Tutorial !!!
Great Work Malek.
I have no idea, I couldn’t find the shell in this stupid windows 8 start menu
goto application page , and then enter ctrl+tab, which will list all the programs.
“Command not found”:
I am getting this error while typing SweetTutos after obj creation
can anyone help me.
Ya Thanks it worked for me,
In the cmd prompt instead of SweetTutos, just type ./SweetTutos
On windows 8, goto startup page/ application page then enter ctrl+tab you can see all available programs in the list.Scroll to find GNUstep shell.
Thank you Jay, stay tuned for more tutorials. Feel free to tweet me a request if you need to implement some technique, etc, so I can write a tutorial about it for you 🙂
Thanks guys for the feedback. Actually it has been a while since I wrote this guide, I implemented the GNUStep environment and objective-c compiler in 2011 to learn some Obj-C basics and to see whether it was possible for Windows users to get that to work. I wrote this guide in 2012 so please take into consideration any system or libraries changes 🙂
Malek
For sure Malek.
I may need your help to publish an iPhone app.
Please share your contact details.
Thanks again 🙂
Sure, please send me a private message on twitter so we can share details later on. You can reach me on twitter from the right twitter widget.
Thank you very much for this useful information. I believe the next step would be giving us some hints on how to get a simple UI started. 🙂
Hi, Thanks for your comment, please email me at malek.isims88@gmail.com for any tutorial you want to see online to get you started in iOS, so I can put it on my to-do list and make it to help you 🙂
For windows development with Objective-C, as far as I know, you cannot go further for a UI enhancements with GNUStep.
Le me know.
I’m really interested in cross-platform (read Windows for now) UI programming. Nothing fancy, just creating a Window with the standard GNUStep UI components. As a plus, I’m particularly interested in a “canvas” element and drawing primitives… 🙂
It seems I just found what I was looking for:
http://gnustep.made-it.com/GSPT/xml/Tutorial_en.html
This tutorial has a section on GUI which does exactly what I wanted, a GUI app without using Gorm, just plain code from scratch.
Thanks anyway, your tutorial was the spark which started it all for my Objective-C on Windows fun! 🙂
when i hit make it says command not found
Hi I made all these commands, now what will do? what is the next step? please respond.
Hi 🙂
As a next step, you can install a visual editor to work with like D.S Shneider pointed out above (http://gnustep.made-it.com/GSPT/xml/Tutorial_en.html)
I get a error:
DenisDesktop1 /c/MyProject
$ make
GNUmakefile:5: /common.make: No such file or directory
GNUmakefile:15: /tool.make: No such file or directory
make: *** No rule to make target ‘tool.make’ . Stop
Install in Win7 as described here:
http://www.gnustep.org/windows/installer.html
Can you give me some pointers ?
Denis
Solved.
I reinstalled GNUstep again.
I suspect I had installed in the wrong order first time.
Now working 🙂
D.
I’m glad I found this. I tried many ways but couldn’t compile it. Thanks Sweettos!
I am glad to help 🙂
I have completed all steps correctly. However, in the last step where i need to type “SweetTutos” it is not working and replying “command not found”. Please Help
Try this command
./SweetTutos.exe
The ./ explicitly points to the directory in which the exe is available.
I’m trying to use the make command inside the right directory. I tried:
make
make GNUmakefile.mak
make main.m
make GNUmakefile
make main
And neither option works. Any help?
Thank you Fatchul,
I too faced the same problem. Your inputs helped me to compile it.
Thanks alot.
Super Except ./SweetTutos.exe
Fight and die in the Syrian Army of course you leech rat
nice tutorial, work for windows 10