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. nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

    启动nginx时报这个错 , 要么用root用户启动 , 要么在配置文件nginx.conf中将server下的listen端口改掉 , 因为在linux中端口号小于1024都是需要root权限的

  2. JAVA算数运算符

    算数运算符 序号 算数运算符 含义用法 特殊含义用法 1 + 加法 字符串连接 2 - 减法   3 * 乘法   4 / 除法   5 % 取余   实例: public class Test{ p ...

  3. Java基础-面板组件

  4. div滚动到页面顶端后固定住

    <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title> ...

  5. POJ 1703

    种类并查集,基本思想是每次压缩路径都必须同时更新子节点和根节点的关系,这种关系是通过子节点和父亲节点的关系,以及父亲节点与根节点的关系运算出来. 压缩路径的findme();参考了大神的代码,做的第二 ...

  6. 导出api文档

    Export,选中项目或者需要导出api的类,右键 java-->javadoc configure,选择C:\Program Files\Java\jdk1.6.0_29\bin\javado ...

  7. transform的使用

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  8. HDFS副本机制&负载均衡&机架感知&访问方式&健壮性&删除恢复机制&HDFS缺点

    副本机制 1.副本摆放策略 第一副本:放置在上传文件的DataNode上:如果是集群外提交,则随机挑选一台磁盘不太慢.CPU不太忙的节点上:第二副本:放置在于第一个副本不同的机架的节点上:第三副本:与 ...

  9. Windows 2008 IIS7.0安装FTP教程 IIS7.5 配置多用户FTP

    一. 安装IIS.右键[我的电脑],选择[管理]打开.     选择[角色],选择[添加角色]打开.                   二. 配置DOS.输入: CACLS "%Syste ...

  10. 增量升级(省流量更新)的Android客户端实现

    转载与 zhouhuiah的专栏 http://blog.csdn.net/zhouhuiah/article/details/16939937 本文在以上两篇博客的基础上再增加了异常处理,并将生成的 ...