2011-02-07 64 views
4

我刚开始做gcc的Objective-C(到目前为止我只使用XCode)。Gcc不包括Object.h

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

我在忽略什么?

+1

对象已经从... 1995年弃用? – bbum 2011-02-07 22:34:43

回答

4

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

0

如何改变第一行

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

我刚刚被告知Object.h在OS X中很糟糕。 – er4z0r 2011-02-07 22:23:33