如何解决这个winsock错误?

时间:2013-12-16 05:12:46

标签: c++

C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp: In function `int _tmain()':
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:48: error: `getaddrinfo' was not declared in this scope
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:59: error: `freeaddrinfo' was not declared in this scope
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:68: error: `freeaddrinfo' was not declared in this scope
C:\Users\Chan\Desktop\test - fail\winsock2 socket server.cpp:74: error: `freeaddrinfo' was not declared in this scope

使用此标头文件

#include "winsock2.h"
#include "windows.h"
#include "WS2tcpip.h"

1 个答案:

答案 0 :(得分:1)

头文件WS2tcpip.h使用此define:

#if (_WIN32_WINNT >= 0x0600)

这意味着在您的构建中,您应该将_WIN32_WINNT定义为0x600(Vista)或更高版本。这意味着您想要的API在WinXP中不存在。