• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Where there is a dream ,there is hope

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              64 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            今天寫一個(gè)小程序出現(xiàn)了這種問(wèn)題:
            >c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(91) : warning C4005: “AF_IPX”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(460) : 參見(jiàn)“AF_IPX”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(127) : warning C4005: “AF_MAX”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(479) : 參見(jiàn)“AF_MAX”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(163) : warning C4005: “SO_DONTLINGER”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(402) : 參見(jiàn)“SO_DONTLINGER”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(206) : error C2011: “sockaddr”: “struct”類型重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(485) : 參見(jiàn)“sockaddr”的聲明
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2143: 語(yǔ)法錯(cuò)誤 : 缺少“}”(在“常量”的前面)
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2143: 語(yǔ)法錯(cuò)誤 : 缺少“;”(在“常量”的前面)
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2059: 語(yǔ)法錯(cuò)誤 : “常量”
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C2143: 語(yǔ)法錯(cuò)誤 : 缺少“;”(在“}”的前面)
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C4430: 缺少類型說(shuō)明符 - 假定為 int。注意: C++ 不支持默認(rèn) int
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C4430: 缺少類型說(shuō)明符 - 假定為 int。注意: C++ 不支持默認(rèn) int
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(518) : warning C4005: “IN_CLASSA”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(287) : 參見(jiàn)“IN_CLASSA”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(524) : warning C4005: “IN_CLASSB”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(293) : 參見(jiàn)“IN_CLASSB”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(530) : warning C4005: “IN_CLASSC”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(299) : 參見(jiàn)“IN_CLASSC”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(541) : warning C4005: “INADDR_ANY”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(304) : 參見(jiàn)“INADDR_ANY”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(543) : warning C4005: “INADDR_BROADCAST”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(306) : 參見(jiàn)“INADDR_BROADCAST”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(577) : error C2011: “sockaddr_in”: “struct”類型重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(312) : 參見(jiàn)“sockaddr_in”的聲明
            1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(132) : error C2011: “fd_set”: “struct”類型重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(68) : 參見(jiàn)“fd_set”的聲明
            1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(167) : warning C4005: “FD_SET”: 宏重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(102) : 參見(jiàn)“FD_SET”的前一個(gè)定義
            1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(176) : error C2011: “timeval”: “struct”類型重定義
            1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(111) : 參見(jiàn)“timeval”的聲明


            好久沒(méi)寫TCP的程序了,都忘記是怎么回事了,隱約記得解決方法很簡(jiǎn)單。搜索了一下,記錄下來(lái):

            引用鏈接:http://www.cnblogs.com/tonyyang132/archive/2009/10/14/1583110.html

            初看到如此一堆的錯(cuò)誤委實(shí)不爽,但是只要將二者的包含順序調(diào)換一下問(wèn)題就會(huì)解決,原因參見(jiàn)下面那個(gè)鏈接。另外,上述問(wèn)題不僅影響直接包含二者的文件,還影響間接包含的情形。比如,a.h包含了windows.h,b.h包含了winsock2.h,如果在c.h當(dāng)中要引用a.h和b.h,那么正確的順序應(yīng)當(dāng)是b.h先于a.h。當(dāng)然,實(shí)踐當(dāng)中有時(shí)很難找到究竟是哪兩個(gè)文件順序不對(duì)了,終極的解決辦法是,在當(dāng)前工程(就是編譯不過(guò)的這個(gè)工程)所有include語(yǔ)句最前面加上#include <winsock2.h>和#include<windows.h>,世界清靜了。


            關(guān)于WINSOCK.H與winsock2.h中的重定義解決辦法分析
            問(wèn)題描述:在 VC 6.0中使用socket相關(guān)的函數(shù)時(shí)沒(méi)有什么問(wèn)題,可是到了.net下就有以下類似的錯(cuò)誤,
            [C++ Error] winsock2.h(109): E2238 Multiple declaration for 'fd_set'
            [C++ Error] winsock.h(54): E2344 Earlier declaration of 'fd_set'
            [C++ Error] winsock2.h(112): E2146 Need an identifier to declare
            [C++ Warning] winsock2.h(144): W8017 Redefinition of 'FD_SET' is not identical
            [C++ Error] winsock2.h(153): E2238 Multiple declaration for 'timeval'
            [C++ Error] winsock.h(97): E2344 Earlier declaration of 'timeval'
            [C++ Error] winsock2.h(209): E2238 Multiple declaration for 'hostent'
            [C++ Error] winsock.h(153): E2344 Earlier declaration of 'hostent'
            [C++ Error] winsock2.h(222): E2238 Multiple declaration for 'netent'
            [C++ Error] winsock.h(166): E2344 Earlier declaration of 'netent'
            [C++ Error] winsock2.h(229): E2238 Multiple declaration for 'servent'
            [C++ Error] winsock.h(173): E2344 Earlier declaration of 'servent'
            [C++ Error] winsock2.h(241): E2238 Multiple declaration for 'protoent'
            [C++ Error] winsock.h(185): E2344 Earlier declaration of 'protoent'
            [C++ Error] winsock2.h(327): E2238 Multiple declaration for 'in_addr'
            [C++ Error] winsock.h(269): E2344 Earlier declaration of 'in_addr'
            [C++ Error] winsock2.h(385): E2238 Multiple declaration for 'sockaddr_in'
            [C++ Error] winsock.h(319): E2344 Earlier declaration of 'sockaddr_in'
            [C++ Error] winsock2.h(395): E2238 Multiple declaration for 'WSAData'
            [C++ Error] winsock.h(329): E2344 Earlier declaration of 'WSAData'
            [C++ Error] winsock2.h(411): E2146 Need an identifier to declare
            [C++ Warning] winsock2.h(455): W8017 Redefinition of 'SO_DONTLINGER' is not identical
            [C++ Warning] winsock2.h(512): W8017 Redefinition of 'AF_IPX' is not identical
            [C++ Warning] winsock2.h(540): W8017 Redefinition of 'AF_MAX' is not identical
            [C++ Error] winsock2.h(546): E2238 Multiple declaration for 'sockaddr'
            [C++ Error] winsock.h(492): E2344 Earlier declaration of 'sockaddr'
            [C++ Error] winsock2.h(586): E2238 Multiple declaration for 'sockproto'
            [C++ Error] winsock.h(501): E2344 Earlier declaration of 'sockproto'
            [C++ Error] winsock2.h(625): E2238 Multiple declaration for 'linger'
            [C++ Error] winsock2.h(625): E2228 Too many error or warning messages

            Solution:

            This problem arises because windows.h (at least, that version of it) includes not winsock2.h but winsock.h; sadly when Microsoft wrote winsock2.h they chose neither to change windows.h to include winsock2.h, which replaces winsock.h, nor to include windows.h from winsock2.h and then add the definitions for the new Winsock 2 API methods & structures (this might seem reasonable since Winsock 2 does, strictly speaking, replace Winsock 1, but since the API must be fully backwards-compatible the distinction is somewhat meaningless and there's no real benefit to making winsock2.h standalone).

            The fix is thankfully simple: always "#include <winsock2.h>" before windows.h.

            However, you must remember that if windows.h has been included by (for example) a higher-level header file that is subsequently including your header file, it's too late - so you must make sure that the higher-level header files respect this convention also.

            It is however rarely necessary to modify the header files of libraries or other code modules you are using just because you include their header files, and their header files include windows.h - you can just include winsock2.h before you include the library's header files.


            在包含jrtplib有時(shí)候我也遇到這個(gè)問(wèn)題,解決方法與之相同。一句話,在#include<windows.h>之前 #include <winsock2.h> 問(wèn)題就可以解決。

            問(wèn)題描述]
               在包含了<windows.h>以及<winsock2.h>的工程中,編譯有時(shí)會(huì)出現(xiàn)如
            下錯(cuò)誤:

                 error C2011: 'fd_set' : 'struct' type redefinition
                 error C2011: 'timeval' : 'struct' type redefinition
                                 ....
                 error C2375: 'accept' : redefinition; different linkage
            [原因分析]
               主要原因是因?yàn)?lt;windows.h>中包含了<winsock.h>頭文件,由于其版
            本的不同,導(dǎo)致出
            現(xiàn)上述的錯(cuò)誤。<windows.h>中相關(guān)代碼如下:
                           #ifndef WIN32_LEAN_AND_MEAN
                           #include <cderr.h>
                           #include <dde.h>
                           #include <ddeml.h>
                           ........
                            #ifndef _MAC
                           #include <winperf.h>
                           #include <winsock.h>
                           #endif
                            .......

                           #include <commdlg.h>
                           #endif
                           #endif
            [解決方案]
                由以上代碼可以看出如果在沒(méi)有定義WIN32_LEAN_AND_MEAN宏
            的大前
            提下windows.h有可能包含winsock.h 頭文件,因此我們得出一個(gè)很簡(jiǎn)單
            的解決方
            法就是在包含<windows.h>之前定義WIN32_LEAN_AND_MEAN宏,如
            下所示:
            #define WIN32_LEAN_AND_MEAN
            #include <windows.h>

            posted on 2010-12-07 15:30 IT菜鳥(niǎo) 閱讀(1160) 評(píng)論(0)  編輯 收藏 引用 所屬分類: TCP/IP

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            欧美麻豆久久久久久中文| 午夜人妻久久久久久久久| 久久精品国产99久久久古代| 怡红院日本一道日本久久| 中文字幕亚洲综合久久菠萝蜜| 99久久夜色精品国产网站| 久久综合亚洲色一区二区三区| 国产AⅤ精品一区二区三区久久| 青青草原综合久久| 久久最新免费视频| 婷婷伊人久久大香线蕉AV| 国内精品久久久久影院日本| 久久国产成人精品麻豆| 久久这里都是精品| yellow中文字幕久久网| 久久精品国产清自在天天线 | 久久强奷乱码老熟女网站| 亚洲精品美女久久久久99| 国产精品久久免费| 狠狠色婷婷久久一区二区三区| 国产精品久久亚洲不卡动漫| 一级A毛片免费观看久久精品| 久久精品免费网站网| 国产精品久久久久久搜索| 中文字幕久久精品无码| 久久久久99这里有精品10 | 日本道色综合久久影院| 亚洲乱亚洲乱淫久久| 久久人人超碰精品CAOPOREN| 18禁黄久久久AAA片| 人妻少妇久久中文字幕| 99国内精品久久久久久久| 久久99久久成人免费播放| 免费观看久久精彩视频| 久久久中文字幕日本| 77777亚洲午夜久久多喷| 国内精品久久久久久久久| 久久99精品久久久久久水蜜桃| 精品久久久久久中文字幕| 99久久精品国产一区二区蜜芽| 久久综合丁香激情久久|