1

我在我的项目中使用了很多包含(但每个头文件都使用像

#ifndef _HEADER_H 
#define _HEADER_H
...
#endif

现在我从 ws2ipdef.h 得到这个错误(自动包含在 windows.h 中):

c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : error C2146: syntax error : missing ';' before identifier 'IN6_ADDR_EQUAL'
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : error C2433: 'Boolean' : 'inline' not permitted on data declarations
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(337) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(344) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(344) : warning C4508: 'IN6_ADDR_EQUAL' : function should return a value; 'void' return type assumed
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C2146: syntax error : missing ';' before identifier 'IN6_IS_ADDR_UNSPECIFIED'
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C2433: 'Boolean' : 'inline' not permitted on data declarations
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C2086: 'int Boolean' : redefinition
1>        c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : see declaration of 'Boolean'
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(355) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(367) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(367) : warning C4508: 'IN6_IS_ADDR_UNSPECIFIED' : function should return a value; 'void' return type assumed

在 Interface.h (包含在其他一些文件中)我使用:

#define WIN32_LEAN_AND_MEAN

// sockets
#include <winsock2.h>
#include "windows.h"
#include <ws2tcpip.h>

我该如何解决这个问题或任何提示?

谢谢

4

2 回答 2

0

尝试使用#pragma once而不是 ifndef 保护,它指定编译器在编译源代码文件时只包含(打开)一次文件。http://msdn.microsoft.com/en-us/library/4141z1cx.aspx

于 2012-11-14T10:09:26.723 回答
0

在 Interface.h 中使用额外的 ifndef 保护解决了它

#ifndef _READERCOMMUNICATION_H
#define WIN32_LEAN_AND_MEAN // to exlude some unnecessary windows headers (see windows.h)

// sockets
//#include <winsock2.h> // winsock 1 is enough for my project
#include <windows.h>
#include <ws2tcpip.h>
#endif 
于 2012-11-15T14:17:34.863 回答