无法在Ubuntu上编译Objective-C代码 [英] Unable to compile Objective-C code on Ubuntu

查看:138
本文介绍了无法在Ubuntu上编译Objective-C代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这段代码...

So I have this piece of code...

/**
 * cdb.m
 * Copyright (C) 2013 Naveen Mathew. All rights reserved.
 */

#import <objc/Object.h>
#import "cdb.h"
#import <stdio.h>
#import <stdlib.h>

@implementation CDB : Object
{

}

- (int) main {
    printf("Hello world");
    return 0;
}

@end

int main(void)
{
    CDB *myNumber = [CDB new]; // equal to [[Number alloc] init]
    [myNumber main];

    return 0;
}

,我想在Ubuntu 13.04中编译它,但没有GNUStep给我的所有废话.因此,我使用GNU Objective C运行时(gobjc),但在编译时得到以下信息...

and I want to compile it in Ubuntu 13.04 but without all the crap that GNUStep gives me. So I use the GNU Objective C runtime (gobjc) but when I compile I get the following...

clang -Wall -lobjc -o cdb cdb.m -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include
cdb.m:25:21: warning: class method '+new' not found (return type defaults to
      'id') [-Wobjc-method-access]
        CDB *myNumber = [CDB new]; // equal to [[Number alloc] init]
                        ^    ~~~
1 warning generated.

当我运行程序时,出现了段错误...我正在使用gobjc 4.7.我用gobjc 4.6尝试过...它可以编译,但仍然出现分段错误...

and when I run the program I get a segmentation fault... I'm using gobjc 4.7. I tried it with gobjc 4.6... it compiles but I still get a segmentation fault...

推荐答案

我认为某些古老的运行时已实现+ new和新朋友.我认为,对于像gnustep-runtime这样的较新的运行时(包括GCC附带的运行时,这是非常不同的),我认为,您必须使用category或其他方式实现自己的目标.您可以只剪切&粘贴GNUstep的NSObject的实现,但是它可能对您来说太棘手,因为它执行的工作是在malloc前面加上keep counter等,否则您可能想要实现自己的方式来维护引用计数,例如使用哈希映射或其他方法.如果仅GNUstep-base对您来说太多了,您还可以尝试使用ObjFW之类的替代框架.

I think some ancient runtime has +new and friends implemented. For newer runtime like gnustep-runtime including one came with GCC which is very different, I think, you must implement your own craps using category or whatsoever. You can just cut & paste GNUstep's implementation of NSObject but it could be too tricky for you as it does things like prefixing the malloc with retain counter et al, else you may want to implement your own way to maintain ref counting like using hash map or anything. You may also try alternate framework like ObjFW if GNUstep-base alone has too much craps for you.

这篇关于无法在Ubuntu上编译Objective-C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆