discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cannot compile objective c


From: David Chisnall
Subject: Re: cannot compile objective c
Date: Thu, 26 Jan 2012 17:12:08 +0000

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.

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:

$ cat example.m
#import <Foundation/Foundation.h>

int main(void)
{
        @autoreleasepool {
                NSLog(@"There, that's not so hard, is it?");
        }
        return 0;
}

$ clang -fobjc-arc `gnustep-config --objc-flags` `gnustep-config --base-libs` 
example.m 
$ ./a.out
2012-01-21 16:00:18.972 a.out[43521] There, that's not so hard, is it?

> i have tried everything i could find on the web, nothing worked. 

Really?  This is the first hit I got when I typed 'GNUstep tutorial' into 
DuckDuckGo:

http://gnustep.made-it.com/GSPT/xml/Tutorial_en.html

David

-- Sent from my Difference Engine






reply via email to

[Prev in Thread] Current Thread [Next in Thread]