虽然很折腾,但当看到程序输出那一刻,心里一阵暗爽。
好了,先把文件建立好。
就是.h和.m啦。不能搞复杂了,因为这是第一个,so简单点。
#include <Foundation/NSObject.h>
@interface Say: NSObject
{
}
- (void) sayHello;
- (void) sayHelloTo: (NSString *)name;
@end
#import "say.h"
#import <Foundation/Foundation.h>
@implementation Say
- (void) sayHello
{
NSLog(@"Hello World");
}
- (void) sayHelloTo: (NSString *)name
{
NSLog(@"Hello World, %@", name);
}
@end
#import "say.h"
#import <Foundation/Foundation.h>
int main (void)
{
id speaker;
NSString *name = @"GNUstep !";
NSAutoreleasePool *pool;
pool = [NSAutoreleasePool new];
speaker = [[Say alloc] init];
[speaker sayHello];
[speaker sayHelloTo:name];
RELEASE(speaker);
RELEASE(pool);
}
这时候终于的是写makefile文件:
GNUSTEP_MAKEFILES = /../../GNUstep/System/Library/Makefiles
include $(GNUSTEP_MAKEFILES)/common.make
# 编译生成的目标
TOOL_NAME = say
# 头文件
say_HEARDER_FILES = say.h
# 源文件
say_OBJC_FILES = main.m say.m
# main_OBJC_FILES = $(mycar_HEARDER_FILES:.h=.m) main.m
include $(GNUSTEP_MAKEFILES)/tool.make
然后,直接在gnu环境下执行make就ok啦:
看下截图: