有没有什么方法可以在不使用 GNUStep 的情况下在 ubuntu 上编译 objective c 程序?我想使用默认的 C 标准库,除了使用 Objective-C 的 OOB 语法之外。我现在遇到的问题是,一旦我准备好所有方法,我就需要一种方法来调用它们。在 Mac 中,我只会分配和初始化它,但在 Linux 上,当我尝试编译它时,clang 只会给我一个错误。
#include <stdio.h> // C standard IO library (for printf)
#include <stdlib.h> // C standard library
// Interface
@interface test
-(void)sayHello :(char *)message;
@end
// Implementation
@implementation test
-(void)sayHello :(char *)message {
printf("%s", message);
}
int main(int argc, char *argv[]) {
test *test = [[test alloc] init];
[test sayHello:"Hello world"];
}
最佳答案
您可以使用 gcc 编译 objective-c,但请记住使用 -lobjc 开关,以便编译器知道您使用的是哪种语言。
您还需要包含以下 header :
#import <objc/Object.h>
...并从您的界面扩展对象。在此处查看 objective-c 的 hello world 示例:
http://en.m.wikipedia.org/wiki/List_of_Hello_world_program_examples#O
关于objective-c - 在 ubuntu 上不用 gnustep 编译 objective-c 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16873844/