【问题标题】:Objective-C compilation with makefile yielding unexpected errors?使用 makefile 进行 Objective-C 编译会产生意外错误?
【发布时间】:2017-06-26 17:11:49
【问题描述】:

下面的“Objective-C 编程(第 6 版)显示了这个Hello World

#import <Foundation/Foundation.h>

int main(void)
{
    @autoreleasepool 
    {
        NSLog(@"Programming is fun!");
    }
    return 0;
}

当我尝试使用 GNUStep makefile 编译程序时

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = Hello
Hello_OBJC_FILES = hello.m

include $(GNUSTEP_MAKEFILES)/tool.make

我收到诸如

之类的错误
hello.m: In function 'main':
hello.m:5:2: error: stray '@' in program
hello.m:5:3: error: 'autoreleasepool' undeclared (first use in this function)
hello.m:5:3: note: each undeclared identifier is reported only once for each function it appears in
hello.m:5:19: error: expected ';' before '{' token
hello.m:9:1: warning: control reaches end of non-void function [-Wreturn-type]
make[3]: *** [obj/Hello.obj/hello.m.o] Error 1
make[2]: *** [internal-tool-all_] Error 2
make[1]: *** [Hello.all.tool.variables] Error 2
make: *** [internal-all] Error 2

我做错了吗?我在程序中看不到任何错误,我不确定为什么 makefile 不起作用。

我应该添加我在 Windows 10 上运行

【问题讨论】:

标签: objective-c makefile gnustep


【解决方案1】:

看完这篇我发现了问题(http://gnustep.8.n7.nabble.com/getting-error-autoreleasepool-undeclared-first-use-in-this-function-td32251.html

原来使用@autoreleasepool {} 是语法糖

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// do your stuff

[pool drain];

这个旧方法是 GCC 唯一支持的,你必须切换到 clang 才能使用 Objective-C 2.0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 2017-02-03
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多