Gcc 不包括 Object.h
我刚刚开始用 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’`\
我在忽略什么?
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.
#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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 gcc 找不到 Object.h,它会给出一个错误指示。问题在于 Apple 在 Objective-C 2.0 中删除了
Object
中的大部分方法(或者至少是它的接口)。相反,您应该子类化 NSObject 并包含 Foundation 框架。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