This tutorial is about installing Objective-C and writing a simple Hello World application on a Windows based machine. I’ve tested the following procedure on a Windows 7 machine.
Prerequisites:
- Unix like shell (a text based environment like a super Command Prompt );
- Objective-C compiler;
- “Real” text editor (God forbid to use Word, WordPad or Notepad).
For the first two points we will install GNUstep which is “a free and open version of the Cocoa (formerly known as NeXTSTEP/OpenStep) APIs and tools”, see http://www.gnustep.org/.
The Windows version of GNUstep is located at http://www.gnustep.org/experience/Windows.html
from the Download section you should save on your machine at least GNUstep MSYS System, GNUstep core and GNUstep Devel.
Install the above three packages in the order you’ve downloaded them.
For a simple text editor we will use Notepad++, which can be downloaded from:
chose “Download the current version” and select the first package (the installer). Install Notepad++ on your computer.
Start the GNUstep shell from Start->All Programs->GNUstep->Shell, at a later time you may want to create a link in the Taskbar for launching this faster. You should be presented with a console window in which you can write Unix commands:
Now, let’s code a simple Objective-C program, don’t worry if you see something that you do not understand in the code, this is only to test if the installation has succeeded and to show you how to compile and run a simple program.
Open Notepad++ and paste (or write if you feel inclined to do so) the following example:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSLog (@"Hello World!");
return 0;
}
This file must be saved in the home folder from GUNstep install, on my computer this is located at “C:\GNUstep\home\Paul”. Save the file with the name ending in .m, for e.g. name it hello.m.
Next step – compiling the Objective-C source code, write this command in the GNUstep shell:
gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries hello.m -lgnustep-base –lobjc
you should see something like :
If everything was OK you should end up with a file a.exe (the executable) in your home folder from GNUstep. The code can be run by writing in the shell window ./a, you should see:
0 Ads:
Post a Comment