# Thread: winsock2 on wins

1. ## winsock2 on wins

Im having problems with compiling my project under MSVC 2005. I included "winsock2.h" only once and linked with "ws2_32.lib" but I get loads of errors (no idea why):

Code:
```c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(112) : error C2011: 'fd_set' : 'struct' type redefinition
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(54) : see declaration of 'fd_set'
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(147) : warning C4005: 'FD_SET' : macro redefinition
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(88) : see previous definition of 'FD_SET'
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(156) : error C2011: 'timeval' : 'struct' type redefinition
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(97) : see declaration of 'timeval'
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(212) : error C2011: 'hostent' : 'struct' type redefinition
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(153) : see declaration of 'hostent'
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(225) : error C2011: 'netent' : 'struct' type redefinition
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(166) : see declaration of 'netent'
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(232) : error C2011: 'servent' : 'struct' type redefinition
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(173) : see declaration of 'servent'
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock2.h(244) : error C2011: 'protoent' : 'struct' type redefinition
c:\program files\microsoft visual studio 8\vc\platformsdk\include\winsock.h(185) : see declaration of 'protoent'```
etc..

What is the cause of this?

2. you have conflict between winsock and winsock2

try to move winsock2.h higher ( before other includes)

3. Thanks. That helped.

4. In particular, make sure it is always before <windows.h>, or #define WIN32_LEAN_AND_MEAN before including <windows.h>. The macro prevents the header from including winsock, along with a load of other stuff that's rarely needed.

Popular pages Recent additions