问题描述
在项目文件中包括winsock2.h.
Including winsock2.h, in a file of a project.
在-
中遇到许多错误 WinSock2.h(109) : error C2011: 'fd_set' : 'struct' type redefinition
与相应的-
WinSock.h(54) : see declaration of 'fd_set'
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'
我看不到任何头文件中包含winsock.h.
I don't see winsock.h included in any of the headers.
项目中是否有任何设置可能会导致这种情况?
Are there any setting in the project that may be causing this?
编辑
但是,我在另一个文件中使用windows.h:
http://cboard.cprogramming.com/windows-programming/41212- strange-msvc-winsock2-compile-error.html
EDIT
However, I am using windows.h in another file:
http://cboard.cprogramming.com/windows-programming/41212-strange-msvc-winsock2-compile-error.html
编辑2
在标题中,我有:
EDIT 2
In the header I have:
#include <winsock2.h>
#include <iphlpapi.h>
#include "\MyFiles\FileX.h" <-which #include <windows.h>
推荐答案
我的有根据的猜测是包含标头的顺序,即首先包含winsock2.h
(在windows.h
之前具有第一个含义),或者在包含windows.h,可防止Windows.h包含Winsock v1.
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.
#include <winsock2.h>
#include <windows.h>
-或-
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
这篇关于WinSock2.h中的重新定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!