today i've successfully
compiled an objective C program to run in a linux based operating system (ubuntu-LTS [10.04]) by following a number of tutorials in the interwebs.,.,
(following just a single author couldn't get the job done... primarily because updates in operating systems occur so fast.,.,).
Granted that this post will be valid for at least 6 months before all the updates occur again, here are the consolidated steps on how I managed to compile and run an objective-C program in ubuntu 10.04
(1) run the following in your terminal to get all the needed dependencies
sudo apt-get install gobjc gnustep gnustep-make gnustep-common(1.1) later if you get errors similar to these
/usr/share/GNUstep/Makefiles/GNUstep.sh:288: no such file or directory: /usr/share/GNUstep/Makefiles/print_unique_pathlist.shmake sure that you've edited your start-up shell script (
bash.bashrc ) which is found in
/etc folder to have the following lines
#GNUSTEP Environment vars
. /usr/share/GNUstep/Makefiles/GNUstep.shediting the file by just clicking on it would open the file in read-only mode. i used gedit in superuser mode to address this
sudo gedit bash.bashrcafter after editing the bash file, remember to refresh for the updates.,by typing in "bash" in the terminal
bash(2) download the Foundation.h/Foundation library
sudo apt-get install libgnustep-base-dev(3) write test codes
// for the file
hello.h #import <Foundation/Foundation.h>
@interface Hello : NSObject{
NSString* name;
}
+(NSString*) details;
-(NSString*) name;
-(void) setName : (NSString*)newName;@end // for the file
hello.m#include "hello.h"
@implementation Hello
+(NSString*) details {
return @"This is a string."; }
-(NSString*) name {
return name; }
-(void) setName: (NSString*)newName {
[name release];
name = [newName retain];
}
@end //for the file
helloworld.m #include "hello.h" int main(int n, const char* argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString* s = [Hello details];
printf("Result from a static call: %s\n", [s UTF8String]); Hello* hello = [[Hello alloc] init];
printf("Name is not initialized: %s\n", [[hello name] UTF8String]); [hello setName: @"Jeff"];
printf("Your name is %s\n", [[hello name] UTF8String]);
[pool drain];
return 0;
}(4) compile using a
makefile i've set my Filename (patterned after FatVat's tutorial) to '
GNUmakefile' which contained the following terminal commands
include $(GNUSTEP_MAKEFILES)/common.make
APP_NAME = Hello Hello_OBJC_FILES = hello.m helloworld.m include $(GNUSTEP_MAKEFILES)/application.make or if you want to compile your files individually you make use
gcc `gnustep-config --objc-flags` -o test test.m -lobjc -lgnustep-base where
test.m is your implementation file and
test is the name you've given itand that's pretty much it... This topic still is very interesting for me., now that i've been looking at the blogs of people who claim to have installed the cocoa.h library that can be used for GUI.
◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇