First, I installed the GNU Objective C compiler. Next, I decided to set up a development environment. After a quick search I have found that GNUstep is what I need: "GNUstep is a cross-platform, object-oriented framework for desktop application development....GNUstep is generally compatible with the OpenStep specification and with recent developments of the MacOS (Cocoa) API...". Please see: http://www.gnustep.org/. I installed GNUstep via the Synaptic tool: I simply searched for "GNUstep" and then installed the relevant packages.
Then, I compiled an example form the following link:
http://www.gnustep.org/
I created a directory named "objc" and created two text files shown below there:
source.m:
#include
/*
* The next #include line is generally present in all Objective-C
* source files that use GNUstep. The Foundation.h header file
* includes all the other standard header files you need.
*/
#include
/*
* Declare the Test class that implements the class method (classStringValue).
*/
@interface Test
+ (const char *) classStringValue;
@end
/*
* Define the Test class and the class method (classStringValue).
*/
@implementation Test
+ (const char *) classStringValue;
{
return "This is the string value of the Test class";
}
@end
/*
* The main() function: pass a message to the Test class
* and print the returned string.
*/
int main(void)
{
printf("%s\n", [Test classStringValue]);
return 0;
}
GNUmakefile:
include $(GNUSTEP_MAKEFILES)/common.
TOOL_NAME = LogTest
LogTest_OBJC_FILES = source.m
include $(GNUSTEP_MAKEFILES)/tool.make
In order to setup the GNUstep "environment", one of the following scripts should be run:
/usr/share/GNUstep/Makefiles/
/usr/share/GNUstep/Makefiles/
Note that the paths are installation specific. As I used bash and don't bother to maintain user settings being the only user, I added the following lines to my bash global settings file:
/etc/bash.bashrc:
# Oguz Kupusoglu @ 20 Nov 2008
. /usr/share/GNUstep/Makefiles/
Then I launched a bash shell and make the build which was a piece of cake:
..objc$ make
This is gnustep-make 2.0.2. Type 'make print-gnustep-make-help' for help.
Making all for tool LogTest...
Compiling file source.m ...
Linking tool LogTest ...
In order to run the application I swicthed to the "obj" subdir:
..objc$ ls
GNUmakefile obj source.m
..objc$ cd obj
..objc/obj$ ls
LogTest source.d source.o
..objc/obj$ ./LogTest
This is the string value of the Test class
That is all! Now you have a working Objective C development environment.
No comments:
Post a Comment