Xcode 4 中未声明 struct addrinfo
当使用 Xcode 4 进行一些套接字编程时,我遇到了一些奇怪的错误。尽管我只是从另一个有效的项目中复制了代码(当使用Xcode 3)。该项目主要是用 Objective-C 编写的,但我已经测试过用纯 C 创建另一个框架,但错误仍然存在。
我包括以下框架:
- ApplicationServices.framework
- Cocoa.framework
- AppKit.framework
- Foundation.framework
也没有添加链接器标志。
但是,还存在其他函数,例如 getaddrinfo(它使用 addrinfo
本身!)。有什么想法吗?
I'm running in to some strange errors when dabbling in some socket programming using Xcode 4. I get the error that addrinfo
is undeclared, despite me simply copying the code from another project that did work (when using Xcode 3). The project is mainly in Objective-C, but I've tested creating another framework with plain C, and the error still remains.
I have the following frameworks included:
- ApplicationServices.framework
- Cocoa.framework
- AppKit.framework
- Foundation.framework
No added linker flags either.
However, other functions such as getaddrinfo (that uses addrinfo
itself!) exists. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个问题与 IDE 无关,而是一个语言问题。 C(以及 Objective-c)和 C++(之前的项目是=)中处理结构的方式明显不同。所以我将这一行更改
为:
This issue wasn't IDE-related, it was a language issue. How structs are treated is apparently different in C (and thus Objective-c) and C++ (which the previous projects were=. So I changed the line
To:
你有正确的进口吗?
Have you got the correct imports?
快速 grep 显示 struct addrinfo 是在中声明的。尝试明确地包括这一点。 (您的 Xcode 3 项目可能已在其前缀文件中包含该文件或包含它的其他标头。)
A quick grep shows that struct addrinfo is declared in <netdb.h>. Try explicitly including that. (Your Xcode 3 project may have included that, or some other header that includes it, in its prefix file.)