Objective-C on Windows? Yes, you can!

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.

  1. 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.

The environment is composed of four packages, as shown below :

Objective-C

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

Once you finish installing packages, you can start programming in Objective-C :]

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*******
//
#import 

int 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:

Objective-C

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.

Objective-C

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

Objective-C
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:

Objective-C

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.
Objective-C

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.

Objective-C

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!

Malek
iOS developer with over than 11 years of extensive experience working on several projects with different sized startups and corporates.

47 Comments

  1. great tutorial. But right at the end you need to type ./SweetTutos
    (that is dot forwardslash before the executable filename)

    many thanks

  2. 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.

  3. 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)

  4. 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’

  5. 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.

  6. 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!

  7. “Command not found”:
    I am getting this error while typing SweetTutos after obj creation
    can anyone help me.

  8. 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.

  9. 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 🙂

  10. 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

  11. For sure Malek.
    I may need your help to publish an iPhone app.
    Please share your contact details.

    Thanks again 🙂

  12. 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.

  13. 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. 🙂

  14. 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.

  15. 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… 🙂

  16. 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

  17. Solved.
    I reinstalled GNUstep again.
    I suspect I had installed in the wrong order first time.
    Now working 🙂

    D.

  18. I’m glad I found this. I tried many ways but couldn’t compile it. Thanks Sweettos!

  19. 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

  20. Try this command
    ./SweetTutos.exe
    The ./ explicitly points to the directory in which the exe is available.

  21. 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?

  22. Thank you Fatchul,

    I too faced the same problem. Your inputs helped me to compile it.

    Thanks alot.

Comments are closed.