- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我一直在学习如何通过 C++ 在 Windows 中进行网络编程,进展顺利,除了我遇到了一个问题,我现在大约 3-4 天都无法解决,我正在使用Dev-C++ 5.5.3(Orwell),编译器为TDM-GCC 4.7.1。我在链接器参数中添加了 "-lwsock32"(不带引号)。一切正常除了 “freeaddrinfo” 和 “getaddrinfo”,下面是其中两个函数的内容。
undefined reference to `imp_getaddrinfo@16'
undefined reference to `imp_freeaddrinfo@4'
我在某处读到它要求我定义我想要的 Windows 版本使用,所以我根据需要定义了_WINNT_WIN32 0x0601,但没有用。这是我的代码(缩写):
#define _WINNT_WIN32 0x0601
#include <ws2tcpip.h>
#include <winsock2.h>
#include <stdio.h>
#define DEFAULT_PORT "27015"
// server
int main()
{
WSADATA wsaData;
ZeroMemory(&wsaData,sizeof(wsaData));
int nResult = WSAStartup(MAKEWORD(2,2),&wsaData);
if(nResult != 0)
{
printf(TEXT("WSAStartup function failed, value: %d\n"),nResult);
Sleep(5000);
return 0001;
}
else
printf(TEXT("WSAStartup function has succeeded! value: %d\n"),nResult);
struct addrinfo *result = NULL, *ptr = NULL, hints;
ZeroMemory(&hints,sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
nResult = getaddrinfo(NULL,DEFAULT_PORT,&hints,&result);
if(nResult != 0)
{
printf("getaddrinfo did not return 0... failure...");
WSACleanup();
return 0002;
}
SOCKET ListenSocket = INVALID_SOCKET;
ListenSocket = socket(result->ai_family,result->ai_socktype,result->ai_protocol);
if (ListenSocket == INVALID_SOCKET)
{
printf("Error at socket():%ld\n",WSAGetLastError());
freeaddrinfo(result);
WSACleanup();
return 0003;
}
nResult = bind(ListenSocket, result->ai_addr,(int)result->ai_addrlen);
if(nResult == SOCKET_ERROR)
{
printf("bindfailed with error %d\n",WSAGetLastError());
freeaddrinfo(result);
closesocket(ListenSocket);
WSACleanup();
return 0004;
}
freeaddrinfo(result);
if(listen(ListenSocket,SOMAXCONN) == SOCKET_ERROR)
{
printf("lISTEN FAILED WITH ERROR %LD\n",WSAGetLastError());
closesocket(ListenSocket);
}
return 1337^9001;
}
谢谢。
最佳答案
确保在预处理器定义中定义了 _WIN32_WINNT,并使用 -lWs2_32
see here
关于c++ - 对 imp_getaddrinfo 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21022654/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!