Gcc不包括Object.h

时间:2011-02-07 21:32:01

标签: objective-c gcc

我刚开始用gcc做Objective-c(到目前为止我只使用了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

一旦我尝试编译我得到的东西:

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’

我觉得包含Object.h并不是很有效。 我搜索了包含Object.h的内容并得到了这个:

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

此外,GCC输出提示编译器 实际上正在该路径中搜索。

 #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’`\

我在俯瞰什么?

2 个答案:

答案 0 :(得分:4)

如果gcc找不到Object.h,它会给出一个错误指示。问题是Apple在Objective-C 2.0中从Object(或至少是它的接口)中删除了大部分方法。相反,您应该继承NSObject并包含Foundation框架。

答案 1 :(得分:0)

如何将第一行更改为

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