C Win 7 64位和未定义的对getaddrinfo的引用
我有一段示例代码:C Win 7 64位和未定义的对getaddrinfo的引用,c,winsock2,C,Winsock2,我有一段示例代码: #include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h> // link with Ws2_32.lib #pragma comment (lib, "Ws2_32.lib") //... if ((err = getaddrinfo(hostname, service, &hints, &res)) != 0) { printf("error
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
// link with Ws2_32.lib
#pragma comment (lib, "Ws2_32.lib")
//...
if ((err = getaddrinfo(hostname, service, &hints, &res)) != 0)
{
printf("error %d\n", err);
return 1;
}
我犯了一个错误。如何做到这一点?如果您的目标不是Windows 2000或更旧版本,那么将
WINVER
设置为0x501应该可以让您的代码正确生成
gcc -DWINVER=0x501 ...
(或者在源代码中包含任何Windows标头之前使用
#define
。如果您的目标不是Windows 2000或更旧版本,则设置WINVER
到0x501应该可以正确生成代码
gcc -DWINVER=0x501 ...
(或者在源代码中包含任何Windows标题之前使用
#define
。看起来gcc的标题已经过时了。您可以尝试#包括。这就是你对旧版本的微软编译器所做的。看起来gcc的头已经过时了。您可以尝试#包括。这就是您对旧版本的Microsoft编译器所做的。