2010-12-15 61 views
1

整个错误是:错误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> 

我还将WS2_32.lib添加到Visual Studio 2010中的链接程序中。

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

+0

http://stackoverflow.com/questions/3531474/socklen-t-undeclared-when-compiling-c-code – 2010-12-15 19:35:42

回答

11

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

1

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

相关问题