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). 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.fram开发者_如何学Pythonework
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.)
精彩评论