14
Jul

Install GNUStep and come to the GNUStep shell prompt!
File: hello.h


#include <Foundation/Foundation.h>

@interface Hello: NSObject
{

}
- (void) sayHelloTo: (NSString *)name;
@end

File: hello.m

#include <Foundation/Foundation.h>
#include "hello.h"

@implementation Hello

- (void) sayHelloTo: (NSString *)name
{
   NSLog(@"Hello World, %@", name);
}

@end

File: main.m

#include <Foundation/Foundation.h>
#include "hello.h"

int main (int argc, const char * argv[])
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   id speaker;
   NSString *name = @"GNUstep ... Sree";
   speaker = [[Hello alloc] init];
   [speaker sayHelloTo:name];

   [speaker release];
   [pool drain];
   return 0;
}

Compile:

gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries hello.m main.m -o Hello -lgnustep-base -lobjc

File created:

-rw-r--r-- 1 sree Administrators 20685 Jul 14 16:18 Hello.d
-rwxr-xr-x 1 sree Administrators 42508 Jul 14 16:18 Hello.exe
-rw-r--r-- 1 sree Administrators   113 Jul 14 16:17 hello.h
-rw-r--r-- 1 sree Administrators   161 Jul 14 16:17 hello.m
-rw-r--r-- 1 sree Administrators   340 Jul 14 16:17 main.m

Run by:
./Hello.exe

Output:

2010-07-14 16:18:25.203 Hello[5716] Hello World, GNUstep ... Sree

, , , , , , , , , , , , ,

Sree
Posted by on 14 Jul 2010 by Sree in Objective C

Add reply

*