discuss-gnustep
[Top][All Lists]
Advanced

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

Re: got error when compile


From: David Chisnall
Subject: Re: got error when compile
Date: Wed, 8 Jul 2009 15:27:29 +0100

On 8 Jul 2009, at 10:42, Apache wrote:

Hi, I'm java developer and start learning objective c using GNUstep

Hi!


say.h
--------
#ifndef _Say_H_
#define _Say_H_

#include <Foundation/NSObject.h>

In general, you should use #import on Objective-C headers, not include, and not put these #ifndef protections on them. Using #import instead of #include automatically prevents multiple-inclusion.

The GNUstep headers work with #include because the GCC people went briefly insane a few years ago that they were going to deprecate #import. A lot of other Objective-C headers, however, will not work with #include.

@interface Say: NSObject
{
}
- (void) sayHello;
- (void) sayHelloTo: (NSString *)name;
@end

Don't forget that you also need an implementation of the class. If you attempt to instantiate a class which doesn't exist then you will get errors.

$ gcc -o main main.m
In file included from main.m:1:
say.h:4:33: Foundation/NSObject.h: No such file or directory
In file included from main.m:1:
say.h:7: error: cannot find interface declaration for `NSObject',
superclass of
`Say'

The problem here is, as it says, that it can't find the location of the headers. If you want to compile like this then you will need to provide a -I command-line option providing the location of the GNUstep headers, and also add -lgnustep-base and an equivalent -L command specifying the location of the GNUstep library.

You are better off using GNUstep Make. This is a set of GNU make files for building GNUstep things. You probably want a GNUmakefile like this:

include $(GNUSTEP_MAKEFILES)/common.make

VERSION = 0.1
TOOL_NAME = example

$(TOOL_NAME)_OBJC_FILES = \
        say.m\
        test.m

include $(GNUSTEP_MAKEFILES)/tool.make

Just put that in a file called GNUmakefile and type 'make'. Note that I'm assuming that you have a say.m file providing the implementation of the class described in say.h. If you don't have one, then your code will compile but will fail to link.

David




reply via email to

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