問(wèn)題描述:在 VC 6.0中使用socket相關(guān)的函數(shù)時(shí)沒(méi)有什么問(wèn)題,可是到了.net下就有以下類似的錯(cuò)誤,
[C++ Error] winsock2.h(109): E2238 Multiple declaration
for 'fd_set'
[C++ Error] winsock.h(54): E2344 Earlier declaration of 'fd_set' [C++ Error] winsock2.h(112): E2146 Need an identifier to declare [C++ Warning] winsock2.h(144): W8017 Redefinition of 'FD_SET' is not identical [C++ Error] winsock2.h(153): E2238 Multiple declaration for 'timeval' [C++ Error] winsock.h(97): E2344 Earlier declaration of 'timeval' [C++ Error] winsock2.h(209): E2238 Multiple declaration for 'hostent' [C++ Error] winsock.h(153): E2344 Earlier declaration of 'hostent' [C++ Error] winsock2.h(222): E2238 Multiple declaration for 'netent' [C++ Error] winsock.h(166): E2344 Earlier declaration of 'netent' [C++ Error] winsock2.h(229): E2238 Multiple declaration for 'servent' [C++ Error] winsock.h(173): E2344 Earlier declaration of 'servent' [C++ Error] winsock2.h(241): E2238 Multiple declaration for 'protoent' [C++ Error] winsock.h(185): E2344 Earlier declaration of 'protoent' [C++ Error] winsock2.h(327): E2238 Multiple declaration for 'in_addr' [C++ Error] winsock.h(269): E2344 Earlier declaration of 'in_addr' [C++ Error] winsock2.h(385): E2238 Multiple declaration for 'sockaddr_in' [C++ Error] winsock.h(319): E2344 Earlier declaration of 'sockaddr_in' [C++ Error] winsock2.h(395): E2238 Multiple declaration for 'WSAData' [C++ Error] winsock.h(329): E2344 Earlier declaration of 'WSAData' [C++ Error] winsock2.h(411): E2146 Need an identifier to declare [C++ Warning] winsock2.h(455): W8017 Redefinition of 'SO_DONTLINGER' is not identical [C++ Warning] winsock2.h(512): W8017 Redefinition of 'AF_IPX' is not identical [C++ Warning] winsock2.h(540): W8017 Redefinition of 'AF_MAX' is not identical [C++ Error] winsock2.h(546): E2238 Multiple declaration for 'sockaddr' [C++ Error] winsock.h(492): E2344 Earlier declaration of 'sockaddr' [C++ Error] winsock2.h(586): E2238 Multiple declaration for 'sockproto' [C++ Error] winsock.h(501): E2344 Earlier declaration of 'sockproto' [C++ Error] winsock2.h(625): E2238 Multiple declaration for 'linger' [C++ Error] winsock2.h(625): E2228 Too many error or warning messages Solution: This problem arises because windows.h (at least, that version of it) includes not winsock2.h but winsock.h; sadly when Microsoft wrote winsock2.h they chose neither to change windows.h to include winsock2.h, which replaces winsock.h, nor to include windows.h from winsock2.h and then add the definitions for the new Winsock 2 API methods & structures (this might seem reasonable since Winsock 2 does, strictly speaking, replace Winsock 1, but since the API must be fully backwards-compatible the distinction is somewhat meaningless and there's no real benefit to making winsock2.h standalone). The fix is thankfully simple: always "#include <winsock2.h>" before windows.h. However, you must remember that if windows.h has been included by (for example) a higher-level header file that is subsequently including your header file, it's too late - so you must make sure that the higher-level header files respect this convention also. It is however rarely necessary to modify the header files of libraries or other code modules you are using just because you include their header files, and their header files include windows.h - you can just include winsock2.h before you include the library's header files. 在包含jrtplib有時(shí)候我也遇到這個(gè)問(wèn)題,解決方法與之相同。一句話,在#include<windows.h>之前 #include
<winsock2.h> 問(wèn)題就可以解決。 問(wèn)題描述] |