Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redefinition errors in WinSock2.h [duplicate]

Including winsock2.h, in a file of a project.

Getting many errors in -
WinSock2.h(109) : error C2011: 'fd_set' : 'struct' type redefinition
with a corresponding -
WinSock.h(54) : see declaration of 'fd_set'

I don't see winsock.h included in any of the headers.

Are there any setting in the project that may be causing this?

EDIT
However, I am using windows.h in another file:
http://cboard.cprogramming.com/windows-programming/41212-strange-msvc-winsock2-compile-error.html

EDIT 2
In the header I have:

#include <winsock2.h>   #include <iphlpapi.h> #include "\MyFiles\FileX.h" <-which #include <windows.h>  
like image 574
T.T.T. Avatar asked May 11 '11 22:05

T.T.T.


1 Answers

My educated guess would be the order of included headers, i.e. include winsock2.h first (with first meaning before windows.h), or define WIN32_LEAN_AND_MEAN before including windows.h, which prevents windows.h from including winsock v1.

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

-or-

#define WIN32_LEAN_AND_MEAN #include <windows.h> #include <winsock2.h> 
like image 94
Jim Brissom Avatar answered Sep 28 '22 06:09

Jim Brissom