zoukankan      html  css  js  c++  java
  • 解决error C2011: 'fd_set' : 'struct' type redefinition的方法

    首先说明这个问题由于重复定义引起的编译错误。

    先说明解决方法,然后再说是什么原因导致了这个问题。

    解决方法:

    下列任何一种方法都可以。

    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

    注意查看我加粗的两行。

  • 相关阅读:
    MySQL开发规范与使用技巧总结
    Anaconda3(在D盘)安装jieba库具体步骤
    Python的reshape的用法
    oom和cpu负载的定位
    接口安全设计
    恍然间
    java原子类
    设计模式
    微服务
    常见的代码优化
  • 原文地址:https://www.cnblogs.com/ark-zhang/p/3144383.html
Copyright © 2011-2022 走看看