解决error C2011: 'fd_set' : 'struct' type redefinition的方法
http://www.cnblogs.com/ark-zhang/archive/2013/06/19/3144383.html
首先说明这个问题由于重复定义引起的编译错误。
先说明解决方法,然后再说是什么原因导致了这个问题。
解决方法:
下列任何一种方法都可以。
1. 在所有包含windows.h的代码之前加上
#define WIN32_LEAN_AND_MEAN
2. 或者直接在工程的properties( vc6 以上)/Setting(vc6) -> c/c++ -> preprocessor 中添加WIN32_LEAN_AND_MEAN
问题根由:
因为windows.h中包含了<winsock.h>,这个是早期版本(windows socket 1.1)的windows socket 的头文件,而当你自己的文件中因使用最新版本windows socket的函数,需要包含 winsock2.h。而这两个版本都定义fd_set一系列的结构和函数,所以就出现这样的问题。
好,我们看下windows.h的定义,其实看一下这个定义就知道导致问题的原因和解决问题的方法:
#ifndef WIN32_LEAN_AND_MEAN
#include <cderr.h>
#include <dde.h>
#include <ddeml.h>
#include <dlgs.h>
#ifndef _MAC
#include <lzexpand.h>
#include <mmsystem.h>
#include <nb30.h>
#include <rpc.h>
#endif
#include <shellapi.h>
#ifndef _MAC
#include <winperf.h>
#include <winsock.h>
#endif
#ifndef NOCRYPT
#include <wincrypt.h>
#include <winefs.h>
#include <winscard.h>
#endif
解决error C2011: 'fd_set' : 'struct' type redefinition的方法的更多相关文章
- 解决ERROR C2011: 'FD_SET' : 'STRUCT' TYPE REDEFINITION问题
在socket编程的过程中头文件中 #include <windows.h> #include "stdafx.h" #include "WinSock2.h ...
- VC中编译报错:error C2011: 'fd_set' : 'struct' type redefinition
这是头文件包含顺序的问题,原因与解决办法见下面代码的注释. /* 包含下面这两个头文件时,必须把winsock2.h放在前面 否则编译报错,N多的重定义错误:例如 error C2011: 'fd_s ...
- ADO编程:error C2011: 'LockTypeEnum' : 'enum' type redefinition
C++ Code 123 // Import the ADO type library #import "C:\\Program Files\\Common Files\\syste ...
- error C2011: “timespec”:“struct”类型重定义
error C2011: “timespec”:“struct”类型重定义 C++ pthread pthread.h 中的 timespec 和time.h 中的 结构定义重复了 ,同时两个头文件中 ...
- error C2011: “Picture”:“struct”类型重定义
今天引用外来库时出现问题,也许是版本问题. 错误如下: .....\oursun\cincludes\quickdraw.h(309): error C2011: “Picture”:“struct” ...
- configure: error: cannot guess build type; you must specify one解决方法
原文地址:https://blog.csdn.net/hebbely/article/details/53993141 1.configure: error: cannot guess build t ...
- 多.h项目出现的问题:使用了预编译头依然出现error LNK2005:***obj已在***obj中定义与c++ error C2011: “xxx”:“class”类型重定义解决办法
使用了预编译头依然出现error LNK2005:***obj已在***obj中定义 造成该问题的可能性比较多,本人将在今后遇到时添加进来,今天先放出本人遇到的一种情况. 多重包含含有变量定义的.h文 ...
- 【Unity Shader】syntax error: unexpected token 'struct' at line x 错误解决办法
以下代码处出现了syntax error: unexpected token 'struct' at line 33的错误 struct a2v { float4 vertex_position : ...
- 编译Cython代码时遇到的问题: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
使用python setup.py build_ext --inplace命令编译cython代码, 出现以下错误: Compiling cython_example.pyx because it c ...
随机推荐
- PO_PO系列 - 请购单系统分析(案例)
2014-07-01 Created By BaoXinjian
- NeHe OpenGL教程 第四十课:绳子的模拟
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- Tornado (and Twisted) in the age of asyncio》
Tornado (and Twisted) in the age of asyncio>
- C++程序设计原理与实践
std_lib_facilities.h和VS下创建C++程序方法:下载 目录: 001. Hello,World!
- Mac下更改python版本为3.5
mac下默认安装了2.x版本的python , 安装python3.5.1后 , 需要切换一下 在~/.bash_profile中添加如下alias(如果你用的是iterm,那就修改.zshrc) a ...
- SSH学习笔记目录
1.Spring_2000_Spring_Hibernate_HibernateTemplate
- [ActionScript 3.0] AS3.0 动态加载显示内容
可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...
- /dev/shm
/dev/shm/是linux下一个特殊的目录,因为这个目录不在硬盘上,而是在内存里. /dev /shm/需要注意的一个是容量问题,在linux下,它默认最大为内存的一半大小,使用df -h命令可以 ...
- 安装jdk java -version 不是自己所需要的版本
原服务器安装有1.4的jdk,应用需要安装1.6的jdk.安装完毕后在/etc/profile里配置1.6jdk的环境变量后使用命令java -version显示还是原来的1.4的版本. 解决办法: ...
- Reflect
反射技术:其实就是动态加载一个指定的类,并获取该类中的所有的内容.而且将字节码文件封装成对象,并将字节码文件中的内容都封装成对象,这样便于操作这些成员.简单说:反射技术可以对一个类进行解剖. 反射的好 ...