[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cannot compile objective c
From: |
Richard Frith-Macdonald |
Subject: |
Re: cannot compile objective c |
Date: |
Thu, 26 Jan 2012 22:50:06 +0000 |
On 26 Jan 2012, at 17:12, David Chisnall wrote:
> Hello,
>
> The reason for your error should be self-explanatory:
>
>> $ gcc hello.m
>> hello.m:1:35: fatal error: Foundation/Foundation.h: No such file or directory
>> compilation terminated.
>
> Your compiler can't find your Foundation.h header. If you read any GNUstep
> tutorial, you will see GNUstep Make is recommended. If you wish to compile a
> single file like this then you should use a command like:
>
> $ clang `gnustep-config --objc-flags` `gnustep-config --base-libs`
>
> Beyond that, there are several problems with your code:
>
>> #include <Foundation/Foundation.h>
>
> This should be #import, not #include. Objective-C headers are not required
> to guard against multiple inclusion, so you should get into the habit of
> using #include for them.
>
>> NSautoreleasePool*pool=[[nsautoreleasepool alloc] init];
>
> The class is NSAutoreleasePool, not NSautoreleasePool or nsautoreleasepool.
> Objective-C, like C, is case sensitive.
>
>
>> nslog(@"Hello World!\n How the fuck does this work?\n");
>
> This should be NSLog, not nslog. And NSLog automatically adds a newline at
> the end, so the \n is redundant.
The above is all fine ... I agree wholeheartedly.
> Additionally, if you're learning Objective-C, then I would strongly advise
> you to use ARC, which simplifies memory management significantly. In this
> case, the example would be:
This bit is not such good advice (though understandable since David's just put
in a lot of work implementing ARC) since ARC simply doesn't exist for most
systems (and almost all the example code you'll see uses conventional reference
counting).
Following the rationale of simplifying memory management, the best advice would
be to use garbage collection (more widely available than ARC, but still rare),
but I wouldn't advocate that either.
As a beginner you should stick to conventional coding ... little-used, bleeding
edge technology is not the place to start.