سؤال

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?

هل كانت مفيدة؟

المحلول

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.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top