C++ WinSock2.h 中的重新定义错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5971332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
redefinition errors in WinSock2.h
提问by T.T.T.
Including winsock2.h, in a file of a project.
包括 winsock2.h,在一个项目的文件中。
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'
在 -WinSock2.h(109) : error C2011: 'fd_set' : 'struct' type redefinition
与相应的 - 中出现许多错误WinSock.h(54) : see declaration of 'fd_set'
I don't see winsock.h included in any of the headers.
我没有看到任何标题中包含 winsock.h。
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
编辑
但是,我在另一个文件中使用 windows.h:http:
//cboard.cprogramming.com/windows-programming/41212-strange-msvc-winsock2-compile-error.html
EDIT 2
In the header I have:
编辑 2
在标题中我有:
#include <winsock2.h>
#include <iphlpapi.h>
#include "\MyFiles\FileX.h" <-which #include <windows.h>
回答by Jim Brissom
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.
我有根据的猜测是包含标题的顺序,即winsock2.h
首先包含(第一个含义之前windows.h
),或者在包含之前定义 WIN32_LEAN_AND_MEAN windows.h
,这会阻止 windows.h 包含 winsock v1。
#include <winsock2.h>
#include <windows.h>
-or-
-或者-
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
回答by kiriloff
After some headache: I made sure that an #include "Winsock2.h"
is before any #include "windows.h"
and "#include "Winsock.h"
and this solved the case.
有些头痛后:我确信的#include "Winsock2.h"
是之前的任何#include "windows.h"
和"#include "Winsock.h"
这解决了问题。
I checked the recursive includes, I spotted the header files which include (recursively) some #include "windows.h"
and "#include "Winsock.h"
and write a #include "Winsock2.h"
. in this files, i added #include "Winsock2.h"
as the first include.
我检查递归包括,我看到的头文件,其中包括(递归地)一些#include "windows.h"
和"#include "Winsock.h"
和写#include "Winsock2.h"
。在这个文件中,我添加#include "Winsock2.h"
为第一个包含。
Just a matter of patience, look at includes one by one and establish this order, first #include "Winsock2.h"
then #include "windows.h"
耐心一点,一一查看include并建立这个顺序,先 #include "Winsock2.h"
然后#include "windows.h"