dav
dav

Reputation: 936

Objective-C compilation with makefile yielding unexpected errors?

Following "Programming in Objective-C (6th Edition) shows this Hello World

#import <Foundation/Foundation.h>

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

When I try to compile the program using a GNUStep makefile

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = Hello
Hello_OBJC_FILES = hello.m

include $(GNUSTEP_MAKEFILES)/tool.make

I get errors such as

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

Am I doing something wrong? I can't see any bugs in the program and I'm not sure why the makefile wouldn't work.

I should add I am running on Windows 10

Upvotes: 2

Views: 175

Answers (1)

dav
dav

Reputation: 936

I found the problem after reading this (http://gnustep.8.n7.nabble.com/getting-error-autoreleasepool-undeclared-first-use-in-this-function-td32251.html)

Turns out using @autoreleasepool {} is syntactic sugar for

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

// do your stuff

[pool drain];

This old method is the only one supported by GCC, you will have to switch to clang to use Objective-C 2.0.

Upvotes: 3

Related Questions