我在我的项目中使用了很多包含(但每个头文件都使用标题保护,例如
#ifndef _HEADER_H
#define _HEADER_H
...
#endif
现在我从ws2ipdef.h(自动包含在windows.h中)收到此错误:
c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(336) : error C2146: syntax error : missing ';' before identifier 'IN6_ADDR_EQUAL'
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(336) : error C2433: 'Boolean' : 'inline' not permitted on data declarations
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(336) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(337) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(344) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(344) : warning C4508: 'IN6_ADDR_EQUAL' : function should return a value; 'void' return type assumed
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(354) : error C2146: syntax error : missing ';' before identifier 'IN6_IS_ADDR_UNSPECIFIED'
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(354) : error C2433: 'Boolean' : 'inline' not permitted on data declarations
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(354) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(354) : error C2086: 'int Boolean' : redefinition
1> c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(336) : see declaration of 'Boolean'
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(355) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.h(367) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:program filesmicrosoft sdkswindowsv7.0includews2ipdef.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>
如何解决此问题或任何提示?
感谢
尝试使用 #pragma once
而不是 ifndef guard,它指定编译器在编译源代码文件时仅包含(打开)一次文件。 http://msdn.microsoft.com/en-us/library/4141z1cx.aspx
在 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