开发者

struct addrinfo undeclared in Xcode 4

开发者 https://www.devze.com 2023-03-08 06:18 出处:网络
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

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:

No added linker flags either.

However, other functions such as getaddrinfo (that uses addrinfo itself!) exists. Any ideas?


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

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>. Try explicitly including that. (Your Xcode 3 project may have included that, or some other header that includes it, in its prefix file.)

0

精彩评论

暂无评论...
验证码 换一张
取 消