本文介绍了错误C2065:'socklen_t':未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整个错误是:

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。

I have also added WS2_32.lib to the linker in Visual Studio 2010.

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

What else could cause this problem? I'm just trying to rewrite my simple UDP program to work under Windows.

推荐答案

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

The socklen_t type is defined inside of WS2tcpip.h in windows. This is not transitively included from winsock2.h (AFAICT). You'll need to include WS2tcpip.h manually in order to use the socklen_t type.

这篇关于错误C2065:'socklen_t':未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:23