简体   繁体   English

Xcode 4 中未声明的结构 addrinfo

[英]struct addrinfo undeclared in Xcode 4

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).在使用 Xcode 4 涉足某些套接字编程时,我遇到了一些奇怪的错误。尽管我只是从另一个有效的项目中复制代码(使用 Xcode 3 时),但我得到了addrinfo未声明的错误。 The project is mainly in Objective-C, but I've tested creating another framework with plain C, and the error still remains.该项目主要在Objective-C中,但我已经测试过用普通的C创建另一个框架,错误仍然存在。

I have the following frameworks included:我包含以下框架:

  • ApplicationServices.framework ApplicationServices.framework
  • Cocoa.framework Cocoa.framework
  • AppKit.framework AppKit.framework
  • Foundation.framework基础框架

No added linker flags either.也没有添加 linker 标志。

However, other functions such as getaddrinfo (that uses addrinfo itself.) exists?但是,其他函数,例如 getaddrinfo(使用addrinfo本身。)存在吗? Any ideas?有任何想法吗?

This issue wasn't IDE-related, it was a language issue.此问题与 IDE 无关,而是语言问题。 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 C(以及Objective-c)和C++(以前的项目是=)中的结构处理方式明显不同。所以我改变了这一行

addrinfo hints;

To:至:

struct addrinfo hints;

Have you got the correct imports?你有正确的进口吗?

#import <netinet/in.h>
#import <sys/socket.h>

A quick grep shows that struct addrinfo is declared in <netdb.h>.快速 grep 显示 struct addrinfo 在 <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.) (您的 Xcode 3 项目可能已在其前缀文件中包含它,或包含它的其他一些 header。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM