redefinition errors in WinSock2.h(WinSock2.h 中的重新定义错误)
问题描述
在项目文件中包含 winsock2.h.
Including winsock2.h, in a file of a project.
在 -
中遇到很多错误WinSock2.h(109) : error C2011: 'fd_set' : 'struct' 类型重新定义
带有相应的 -WinSock.h(54) : 见'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-奇怪的msvc-winsock2-compile-error.html
编辑 2
在标题中我有:
EDIT 2
In the header I have:
#include <winsock2.h>
#include <iphlpapi.h>
#include "MyFilesFileX.h" <-which #include <windows.h>
推荐答案
我有根据的猜测是包含标题的顺序,即首先包含 winsock2.h
(第一个含义在 windows 之前.h
),或者在包含 windows.h
之前定义 WIN32_LEAN_AND_MEAN,这样可以防止 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 中的重新定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WinSock2.h 中的重新定义错误


- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01