Solution錛?/font>
This problem arises because (at least, that version of it) includes not but ; sadly when Microsoft wrote they chose neither to change to include , which replaces , nor to include from 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 standalone).
The fix is thankfully simple: always "" before .
However, you must remember that if 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 - you can just include before you include the library's header files.
鍦ㄥ寘鍚玧rtplib鏈夋椂鍊欐垜涔熼亣鍒拌繖涓棶棰橈紝瑙e喅鏂規(guī)硶涓庝箣鐩稿悓銆備竴鍙ヨ瘽錛屽湪#include<windows.h>涔嬪墠 #include <winsock2.h> 闂灝卞彲浠ヨВ鍐熾?br style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">
闂鎻忚堪]
鍦ㄥ寘鍚簡<windows.h>浠ュ強(qiáng)<winsock2.h>鐨勫伐紼嬩腑,緙栬瘧鏈夋椂浼?xì)鍑虹幇濡?br style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">涓嬮敊璇?
error C2011: 'fd_set' : 'struct' type redefinition
error C2011: 'timeval' : 'struct' type redefinition
....
error C2375: 'accept' : redefinition; different linkage
[鍘熷洜鍒嗘瀽]
涓昏鍘熷洜鏄洜涓?lt;windows.h>涓寘鍚簡<winsock.h>澶存枃浠?鐢變簬鍏剁増
鏈殑涓嶅悓錛屽鑷村嚭鐜頒笂榪扮殑閿欒銆?lt;windows.h>涓浉鍏充唬鐮佸涓?
#ifndef WIN32_LEAN_AND_MEAN
#include <cderr.h>
#include <dde.h>
#include <ddeml.h>
........
#ifndef _MAC
#include <winperf.h>
#include <winsock.h>
#endif
.......
#include <commdlg.h>
#endif
#endif
[瑙e喅鏂規(guī)]
鐢變互涓婁唬鐮佸彲浠ョ湅鍑哄鏋滃湪娌℃湁瀹氫箟WIN32_LEAN_AND_MEAN瀹?/font>鐨勫ぇ鍓?br style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">鎻愪笅windows.h鏈夊彲鑳藉寘鍚玾insock.h 澶存枃浠訛紝鍥犳鎴戜滑寰楀嚭涓涓緢綆鍗?br style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">鐨勮В鍐蟲柟娉曞氨鏄湪鍖呭惈<windows.h>涔嬪墠瀹氫箟WIN32_LEAN_AND_MEAN瀹?濡?br style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">涓嬫墍紺?
#define WIN32_LEAN_AND_MEAN
#include <windows.h>