我正在做一个简单的测试,看看我是否可以在没有GNUStep的情况下在Linux上运行Objective-C,所以我在这里按照一个例子来运行它,这里是我的代码:
//WSObject.h
#include <objc/runtime.h>
#include <stdio.h>
@interface WSObject
+ (id) alloc;
- (void) dealloc;
- (void) hello;
@end
//WSObject.m
#include "WSObject.h"
@implementation WSObject
+ (id) alloc {
return class_createInstance(self, 0);
}
+ (void) dealloc {
object_dispose(self);
}
+ (void) hello {
puts("Hello, world");
}
@end
//test.m
#include "WSObject.h"
int main(int argc, const char *argv[]) {
WSObject *obj = [WSObject alloc];
[obj hello];
[obj dealloc];
return 0;
}
当我尝试用gcc test.m -o test -lobjc
编译它时
我收到以下错误:
/tmp/ccDzvsol.o:(.data+0x80): undefined reference to `__objc_class_name_WSObject'
collect2: error: ld returned 1 exit status
任何帮助?