【问题标题】:error C2065: 'socklen_t' : undeclared identifier错误 C2065:“socklen_t”:未声明的标识符
【发布时间】:2010-12-15 19:27:44
【问题描述】:

整个错误是:

Error   1   error C2065: 'socklen_t' : undeclared identifier    c:\users\richard\documents\visual studio 2010\projects\server\server\server.cpp 41  1   Server

这是有问题的行:

int iRcvdBytes=recvfrom(iSockFd, buff, 1024000, 0, (struct sockaddr*)&cliAddr, (socklen_t*)&cliAddrLen);

我有这些标题:

#include <winsock2.h>
#include <windows.h>

#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

我还在 Visual Studio 2010 的链接器中添加了 WS2_32.lib。

还有什么可能导致这个问题?我只是想重写我的简单 UDP 程序以在 Windows 下工作。

【问题讨论】:

标签: c++ visual-c++ socklen-t


【解决方案1】:

socklen_t 类型在 windows 的 WS2tcpip.h 中定义。这不是从 winsock2.h (AFAICT) 传递的。您需要手动包含 WS2tcpip.h 才能使用 socklen_t 类型。

【讨论】:

    【解决方案2】:

    Visual Studio 找不到 socklen_t 类型。 MSDN 说这个函数需要一个 int* 作为最后一个参数,所以转换成那个。

    【讨论】:

      猜你喜欢
      • 2011-02-15
      • 2011-04-16
      • 2011-04-16
      • 2010-12-24
      • 2023-03-04
      • 2011-03-02
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多