Gcc 不包括 Object.h

发布于 2024-10-16 10:35:08 字数 1931 浏览 1 评论 0原文

我刚刚开始用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许你一世情深 2024-10-23 10:35:08

如果 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.

小糖芽 2024-10-23 10:35:08

如何将第一行更改为

#include <objc/Object>

How about changing the first line to

#include <objc/Object>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文