Share via


Linking problem with WinSock2?

Question

Monday, March 27, 2006 11:45 AM

F:\PSDK\Include\WinSock2.h(112) : error C2011: 'fd_set' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(54) : see declaration of 'fd_set'
F:\PSDK\Include\WinSock2.h(147) : warning C4005: 'FD_SET' : macro redefinition
        F:\PSDK\Include\winsock.h(88) : see previous definition of 'FD_SET'
F:\PSDK\Include\WinSock2.h(156) : error C2011: 'timeval' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(97) : see declaration of 'timeval'
F:\PSDK\Include\WinSock2.h(212) : error C2011: 'hostent' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(153) : see declaration of 'hostent'
F:\PSDK\Include\WinSock2.h(225) : error C2011: 'netent' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(166) : see declaration of 'netent'
F:\PSDK\Include\WinSock2.h(232) : error C2011: 'servent' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(173) : see declaration of 'servent'
F:\PSDK\Include\WinSock2.h(244) : error C2011: 'protoent' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(185) : see declaration of 'protoent'
F:\PSDK\Include\WinSock2.h(400) : error C2011: 'sockaddr_in' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(321) : see declaration of 'sockaddr_in'
F:\PSDK\Include\WinSock2.h(410) : error C2011: 'WSAData' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(331) : see declaration of 'WSAData'
F:\PSDK\Include\WinSock2.h(470) : warning C4005: 'SO_DONTLINGER' : macro redefinition
        F:\PSDK\Include\winsock.h(411) : see previous definition of 'SO_DONTLINGER'
F:\PSDK\Include\WinSock2.h(527) : warning C4005: 'AF_IPX' : macro redefinition
        F:\PSDK\Include\winsock.h(469) : see previous definition of 'AF_IPX'
F:\PSDK\Include\WinSock2.h(555) : warning C4005: 'AF_MAX' : macro redefinition
        F:\PSDK\Include\winsock.h(488) : see previous definition of 'AF_MAX'
F:\PSDK\Include\WinSock2.h(561) : error C2011: 'sockaddr' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(494) : see declaration of 'sockaddr'
F:\PSDK\Include\WinSock2.h(601) : error C2011: 'sockproto' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(503) : see declaration of 'sockproto'
F:\PSDK\Include\WinSock2.h(640) : error C2011: 'linger' : 'struct' type redefinition
        F:\PSDK\Include\winsock.h(540) : see declaration of 'linger'
F:\PSDK\Include\WinSock2.h(653) : warning C4005: 'SOMAXCONN' : macro redefinition
        F:\PSDK\Include\winsock.h(553) : see previous definition of 'SOMAXCONN'
F:\PSDK\Include\WinSock2.h(679) : warning C4005: 'FD_READ' : macro redefinition
        F:\PSDK\Include\winsock.h(571) : see previous definition of 'FD_READ'
F:\PSDK\Include\WinSock2.h(682) : warning C4005: 'FD_WRITE' : macro redefinition
        F:\PSDK\Include\winsock.h(572) : see previous definition of 'FD_WRITE'
F:\PSDK\Include\WinSock2.h(685) : warning C4005: 'FD_OOB' : macro redefinition
        F:\PSDK\Include\winsock.h(573) : see previous definition of 'FD_OOB'
F:\PSDK\Include\WinSock2.h(688) : warning C4005: 'FD_ACCEPT' : macro redefinition
        F:\PSDK\Include\winsock.h(574) : see previous definition of 'FD_ACCEPT'
F:\PSDK\Include\WinSock2.h(691) : warning C4005: 'FD_CONNECT' : macro redefinition
        F:\PSDK\Include\winsock.h(575) : see previous definition of 'FD_CONNECT'
F:\PSDK\Include\WinSock2.h(694) : warning C4005: 'FD_CLOSE' : macro redefinition
        F:\PSDK\Include\winsock.h(576) : see previous definition of 'FD_CLOSE'
F:\PSDK\Include\WinSock2.h(1626) : error C2375: 'accept' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(744) : see declaration of 'accept'
F:\PSDK\Include\WinSock2.h(1647) : error C2375: 'bind' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(749) : see declaration of 'bind'
F:\PSDK\Include\WinSock2.h(1666) : error C2375: 'closesocket' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(754) : see declaration of 'closesocket'
F:\PSDK\Include\WinSock2.h(1685) : error C2375: 'connect' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(756) : see declaration of 'connect'
F:\PSDK\Include\WinSock2.h(1706) : error C2375: 'ioctlsocket' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(761) : see declaration of 'ioctlsocket'
F:\PSDK\Include\WinSock2.h(1727) : error C2375: 'getpeername' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(766) : see declaration of 'getpeername'
F:\PSDK\Include\WinSock2.h(1748) : error C2375: 'getsockname' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(771) : see declaration of 'getsockname'
F:\PSDK\Include\WinSock2.h(1771) : error C2375: 'getsockopt' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(776) : see declaration of 'getsockopt'
F:\PSDK\Include\WinSock2.h(1792) : error C2375: 'htonl' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(783) : see declaration of 'htonl'
F:\PSDK\Include\WinSock2.h(1809) : error C2375: 'htons' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(785) : see declaration of 'htons'
F:\PSDK\Include\WinSock2.h(1826) : error C2375: 'inet_addr' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(787) : see declaration of 'inet_addr'
F:\PSDK\Include\WinSock2.h(1843) : error C2375: 'inet_ntoa' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(789) : see declaration of 'inet_ntoa'
F:\PSDK\Include\WinSock2.h(1861) : error C2375: 'listen' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(791) : see declaration of 'listen'
F:\PSDK\Include\WinSock2.h(1879) : error C2375: 'ntohl' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(795) : see declaration of 'ntohl'
F:\PSDK\Include\WinSock2.h(1896) : error C2375: 'ntohs' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(797) : see declaration of 'ntohs'
F:\PSDK\Include\WinSock2.h(1916) : error C2375: 'recv' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(799) : see declaration of 'recv'
F:\PSDK\Include\WinSock2.h(1941) : error C2375: 'recvfrom' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(805) : see declaration of 'recvfrom'
F:\PSDK\Include\WinSock2.h(1967) : error C2375: 'select' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(813) : see declaration of 'select'
F:\PSDK\Include\WinSock2.h(1991) : error C2375: 'send' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(820) : see declaration of 'send'
F:\PSDK\Include\WinSock2.h(2016) : error C2375: 'sendto' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(826) : see declaration of 'sendto'
F:\PSDK\Include\WinSock2.h(2042) : error C2375: 'setsockopt' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(834) : see declaration of 'setsockopt'
F:\PSDK\Include\WinSock2.h(2064) : error C2375: 'shutdown' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(841) : see declaration of 'shutdown'
F:\PSDK\Include\WinSock2.h(2084) : error C2375: 'socket' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(845) : see declaration of 'socket'
F:\PSDK\Include\WinSock2.h(2107) : error C2375: 'gethostbyaddr' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(852) : see declaration of 'gethostbyaddr'
F:\PSDK\Include\WinSock2.h(2126) : error C2375: 'gethostbyname' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(857) : see declaration of 'gethostbyname'
F:\PSDK\Include\WinSock2.h(2144) : error C2375: 'gethostname' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(859) : see declaration of 'gethostname'
F:\PSDK\Include\WinSock2.h(2163) : error C2375: 'getservbyport' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(863) : see declaration of 'getservbyport'
F:\PSDK\Include\WinSock2.h(2182) : error C2375: 'getservbyname' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(867) : see declaration of 'getservbyname'
F:\PSDK\Include\WinSock2.h(2200) : error C2375: 'getprotobynumber' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(871) : see declaration of 'getprotobynumber'
F:\PSDK\Include\WinSock2.h(2217) : error C2375: 'getprotobyname' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(873) : see declaration of 'getprotobyname'
F:\PSDK\Include\WinSock2.h(2237) : error C2375: 'WSAStartup' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(877) : see declaration of 'WSAStartup'
F:\PSDK\Include\WinSock2.h(2255) : error C2375: 'WSACleanup' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(881) : see declaration of 'WSACleanup'
F:\PSDK\Include\WinSock2.h(2272) : error C2375: 'WSASetLastError' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(883) : see declaration of 'WSASetLastError'
F:\PSDK\Include\WinSock2.h(2289) : error C2375: 'WSAGetLastError' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(885) : see declaration of 'WSAGetLastError'
F:\PSDK\Include\WinSock2.h(2306) : error C2375: 'WSAIsBlocking' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(887) : see declaration of 'WSAIsBlocking'
F:\PSDK\Include\WinSock2.h(2323) : error C2375: 'WSAUnhookBlockingHook' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(889) : see declaration of 'WSAUnhookBlockingHook'
F:\PSDK\Include\WinSock2.h(2340) : error C2375: 'WSASetBlockingHook' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(891) : see declaration of 'WSASetBlockingHook'
F:\PSDK\Include\WinSock2.h(2357) : error C2375: 'WSACancelBlockingCall' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(893) : see declaration of 'WSACancelBlockingCall'
F:\PSDK\Include\WinSock2.h(2379) : error C2375: 'WSAAsyncGetServByName' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(895) : see declaration of 'WSAAsyncGetServByName'
F:\PSDK\Include\WinSock2.h(2406) : error C2375: 'WSAAsyncGetServByPort' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(903) : see declaration of 'WSAAsyncGetServByPort'
F:\PSDK\Include\WinSock2.h(2432) : error C2375: 'WSAAsyncGetProtoByName' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(911) : see declaration of 'WSAAsyncGetProtoByName'
F:\PSDK\Include\WinSock2.h(2457) : error C2375: 'WSAAsyncGetProtoByNumber' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(918) : see declaration of 'WSAAsyncGetProtoByNumber'
F:\PSDK\Include\WinSock2.h(2482) : error C2375: 'WSAAsyncGetHostByName' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(925) : see declaration of 'WSAAsyncGetHostByName'
F:\PSDK\Include\WinSock2.h(2509) : error C2375: 'WSAAsyncGetHostByAddr' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(932) : see declaration of 'WSAAsyncGetHostByAddr'
F:\PSDK\Include\WinSock2.h(2532) : error C2375: 'WSACancelAsyncRequest' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(941) : see declaration of 'WSACancelAsyncRequest'
F:\PSDK\Include\WinSock2.h(2552) : error C2375: 'WSAAsyncSelect' : redefinition; different linkage
        F:\PSDK\Include\winsock.h(943) : see declaration of 'WSAAsyncSelect'

All replies (7)

Monday, March 27, 2006 11:57 AM âś…Answered

This is no linking problem. Seams that you are including winsock2.h twice!

Remove one include.


Monday, April 3, 2006 3:46 PM

This answer is rather curt considering there are thousands or reports of the same error listed on google.

While technically correct (actualy probably winsock.h is getting included first) the answer does not provide a work around for the problem.

The fact that a search on microsofts web site returns only this error when google returns 20 pages or more makes one wonder who is kidding who.


Wednesday, December 10, 2008 7:02 AM | 1 vote

add these line after you include <afxsock.h>
#define _WINSOCK2API_
#define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */


Monday, June 28, 2010 9:13 PM | 3 votes

I found out in another thread that windows.h tries to include winsock.h by default, so if you're including winsock2.h, you have to do it before any includes of windows.h.


Wednesday, November 10, 2010 5:54 PM

I was using "using namespace std;" and I was getting this error.  I removed that line and the error went away.


Thursday, December 2, 2010 5:12 PM | 2 votes

Including winsock2.h before Windows.h worked for me. Also, defining WIN32_LEAN_AND_MEAN before Windows.h was included prevents Windows.h from including winsock.h. Thanks


Saturday, May 11, 2013 2:23 AM

Thanks, Locke2002, moving winsock2.h include before windows.h worked for me. 

This did it for me.  I knew the problem (multiple definitions); was trying to search the entire include tree to find mulitiple references to WinSock2.h, but never thought of the old include WinSock.h.

Thanks.  Good answer.

Now I only have ACTUAL LINKING problems <sigh>