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的方法的更多相关文章

  1. 解决ERROR C2011: 'FD_SET' : 'STRUCT' TYPE REDEFINITION问题

    在socket编程的过程中头文件中 #include <windows.h> #include "stdafx.h" #include "WinSock2.h ...

  2. VC中编译报错:error C2011: 'fd_set' : 'struct' type redefinition

    这是头文件包含顺序的问题,原因与解决办法见下面代码的注释. /* 包含下面这两个头文件时,必须把winsock2.h放在前面 否则编译报错,N多的重定义错误:例如 error C2011: 'fd_s ...

  3. ADO编程:error C2011: 'LockTypeEnum' : 'enum' type redefinition

     C++ Code  123   // Import the ADO type library #import "C:\\Program Files\\Common Files\\syste ...

  4. error C2011: “timespec”:“struct”类型重定义

    error C2011: “timespec”:“struct”类型重定义 C++ pthread pthread.h 中的 timespec 和time.h 中的 结构定义重复了 ,同时两个头文件中 ...

  5. error C2011: “Picture”:“struct”类型重定义

    今天引用外来库时出现问题,也许是版本问题. 错误如下: .....\oursun\cincludes\quickdraw.h(309): error C2011: “Picture”:“struct” ...

  6. 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 ...

  7. 多.h项目出现的问题:使用了预编译头依然出现error LNK2005:***obj已在***obj中定义与c++ error C2011: “xxx”:“class”类型重定义解决办法

    使用了预编译头依然出现error LNK2005:***obj已在***obj中定义 造成该问题的可能性比较多,本人将在今后遇到时添加进来,今天先放出本人遇到的一种情况. 多重包含含有变量定义的.h文 ...

  8. 【Unity Shader】syntax error: unexpected token 'struct' at line x 错误解决办法

    以下代码处出现了syntax error: unexpected token 'struct' at line 33的错误 struct a2v { float4 vertex_position : ...

  9. 编译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 ...

随机推荐

  1. Java中的String与常量池

    string是java中的字符串.String类是不可变的,对String类的任何改变,都是返回一个新的String类对象.下面介绍java中的String与常量池. 1. 首先String不属于8种 ...

  2. Mac下finder中无法关闭的小条

    就是这个恶心的小东西,根本无法关闭.其实就是在finder中无意中输入了中文导致的(不是按Alt+F , 就是打开finder然后输入中文) 可以通过继续输入中文然后按esc退出.也可以用下面的设置尽 ...

  3. 容易导致outofmemoryException内存泄漏异常的编码问题

    1.System.Drawing方面的类使用问题 System.Drawing用到了很多系统的资源和非托管代码,所以使用的时候要特别小心,注意内存泄漏(Memory Leak) 2.new byte[ ...

  4. mac打开.caj格式文件

    以为用mac后使用会变得更方便些,写毕设时终于派上用场,可惜啊,mac竟然打不开.caj文件,这意味着什么?相信所有在做毕设的小伙伴们都能懂其中的凄凉.特别是硕士或博士的论文,你得从知网上下上百篇的文 ...

  5. JS获取两个日期的月份差

    function getMonthBetween(startDate,endDate){ startDate=new Date(startDate.replace(/-/g,'/')); endDat ...

  6. [Flex] IFrame系列 —— IFrame嵌入html点击其他组件后页面消失的问题

    在flex建的web项目中,打开index.template.html,将param.wmode = "transparent";添加到以下位置 <script type=& ...

  7. [HDU 4417] Super Mario (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给你n个数,下标为0到n-1,m个查询,问查询区间[l,r]之间小于等于x的数有多少个 ...

  8. [POJ 2063] Investment (动态规划)

    题目链接:http://poj.org/problem?id=2063 题意:银行每年提供d种债券,每种债券需要付出p[i]块钱,然后一年的收入是v[i],到期后我们把本金+收入取出来作为下一年度本金 ...

  9. 安装express后却找不到express的命令

    1.全局安装express npm install -g express 2.执行express命令,创建web项目框架 express -e ejs myweb 会提示 express 不是内部或外 ...

  10. Django网站直接使用supervisor部署

    python manage.py createsuperuser python manage.py migrate 生成网站的supervisor配置文件: echo_supervisord_conf ...