objective-c - 在 ubuntu 上不用 gnustep 编译 objective-c 程序

标签 objective-c c computer-science

有没有什么方法可以在不使用 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/

相关文章:

c - C语言中如何从字符串中获取子字符串?

algorithm - 无法理解解决方案(Turing Machine & Reduction)

algorithm - 在可能不连通的有向图中寻找循环的困惑

iphone - NSString 双重问题

objective-c - 用动画交换 rootViewController

objective-c - boolean 值和核心数据

c - 如何在Ubuntu上获取VS项目的文件路径?

将整数转换为数字数组 [C]

unity3d - 为什么计算机/游戏物理引擎通常是不确定的?

ios - 在 TextView iOS 中的属性字符串末尾添加一个 nsstring