我不能使用MinGW包含winsock2.h

时间:2011-10-24 02:17:23

标签: qt mingw winsock2

我正在使用Qt Creator和MinGW。

我包含了“windows.h”并编译它,但它失败了。错误如下:

In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/windows.h:98:0,
             from util/IdleDetector.h:8,
             from service\PresenceService.cpp:8:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:771:22: error:     expected unqualified-id before string constant
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:1034:95: error: expected identifier before string constant
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/winsock2.h:1034:95: error: expected ',' or '...' before string constant

我认为MinGW路径丢失了,但事实并非如此。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

windows.hwinsock.h还是winsock2.h?两者互不兼容。 winsock2.h旨在取代winsock.h,因此重新声明winsock.h已经声明的很多内容。如果winsock2.h之前包含winsock.h,则winsock2.h会默默禁用winsock.h,一切正常。但如果winsock.h之前包含winsock2.h,则可能会发生各种错误。