开发者

Gcc not including Object.h

I am just starting on doing objective-c with gcc (so far I only used XCode).

#include <objc/Object.h>  
@interface Integer : Object  
{  
int integer;  
}  
- (int) integer;  
-(id) integer: (int) _integer;  
@end

#import "Integer.h"  
@implementation Integer  
- (int) integer  
{  
    return integer;  
}  
- (id) integer: (int) _integer  
{  
    integer = _integer;  
}  
@end

And once I try to compile the stuff I get this:

main.m: In function ‘main’:  
main.m:8: warning: ‘Integer’ may not respond to ‘+new’  
main.m:8: warning: (Messages without a matching method signature  
main.m:8: warning: will be assumed to return ‘id’ and accept  
main.m:8: warning: ‘...’ as arguments.)  
main.m:8: warning: ‘Integer’ may not respond to ‘+new’

Seems to me that the inclusion of Object.h did not quite work. I searched thee includes for Object.h and got this:

find /usr/include/ -name Object.h   
/usr/include//objc/Object.h

Also the GCC output hints that the compiler is actually searching in that path.

开发者_如何学C
 #include "..." search starts here:  
 #include <...> search starts here:  
 /usr/local/include  
 /usr/lib/gcc/i686-apple-darwin10/4.2.1/include  
 /usr/include  
 /System/Library/Frameworks (framework directory)  
 /Library/Frameworks (framework directory)  
End of search list.  
GNU Objective-C version 4.2.1 (Apple Inc. build 5664) (i686-apple-darwin10)
        compiled by GNU C version 4.2.1 (Apple Inc. build 5664).  
GGC heuristics: --param ggc-min-expand=150 --param ggc-min-heapsize=131072  
Compiler executable checksum: 84137cc00ce86c64ee80a91a006f61ae  
main.m: In function ‘main’:  
main.m:8: warning: ‘Integer’ may not respond to ‘+new’  
main.m:8: warning: (Messages without a matching method signature  
main.m:8: warning: will be assumed to return ‘id’ and accept  
main.m:8: warning: ‘...’ as arguments.)  
main.m:8: warning: ‘Integer’ may not respond to ‘+new’`\

What am I overlooking?


If gcc couldn't find Object.h, it would give an error indicating that. The problem is that Apple removed most of the methods from Object (or at least the interface for it) in Objective-C 2.0. Instead, you should subclass NSObject and include the Foundation framework.


How about changing the first line to

&#35;include &lt;objc/Object>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜