2

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

dav
  • 626
  • 4
  • 21
  • I don't know the answer but I wonder if the .m type is not recognized. "hello.m.o" in the error message looks suspicious. This (http://www.gnustep.org/resources/documentation/Developer/Base/ProgrammingManual/manual_14.html) has an example F.1.1 that shows lines for telling `make` how to process the .m suffix. – Phillip Mills Jun 26 '17 at 17:25
  • What's odd is that this (http://www.gnustep.org/resources/documentation/Developer/Base/ProgrammingManual/manual_1.html) provides an Objective-C program (in section 1.5) that compiles successfully with the tool given. – dav Jun 26 '17 at 17:29
  • 1
    Does gcc support `@autoreleasepool` now? It didn't for quite a while. https://stackoverflow.com/q/22275252/603977 https://stackoverflow.com/q/10468901/603977 Your log makes it look like that's still true. – jscs Jun 26 '17 at 17:53

1 Answers1

3

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.

dav
  • 626
  • 4
  • 21