我正在尝试构建并运行一个旧的(以及相当大的(大约100多个源和头文件))VS项目。它最初是使用VS2012和Windows 7编译的,因此我使用的是相同的设置(实际上是Win 7和10)。我是VS的新手,请耐心等待。我的问题是它无法生成此致命错误:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxv_w32.h(16):
fatal error C1189: #error : WINDOWS.H already included.
MFC apps must not #include <windows.h> (utils.cpp)```
我发现很多人都有这个问题。例如,
但是,我找不到适合我的解决方案。首先,据我所知,windows.h
未包含在我们的书面代码中,而是包含在afxv_w32.h
文件中。我有一个utils.h
文件,其中包含有用的函数原型,其中包括一个stdafx.h
文件(如下)。通过“显示包含”选项,我发现stdafx.h
包含了afxwin.h
,最后包含了包含上述错误的afxv_w32.h
;但是,似乎错误始终没有出现。例如:
1> Note: including file: i:\hmcdeliverables\sourcecode\processor\utils.h
1> Note: including file: i:\hmcdeliverables\sourcecode\processor\stdafx.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxwin.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afx.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\new.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxver_.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxv_w32.h
1> Note: including file: C:\Program Files (x86)\Windows Kits\8.0\Include\um\winsdkver.h
1> Note: including file: C:\Program Files (x86)\Windows Kits\8.0\Include\shared\winapifamily.h
1> Note: including file: C:\Program Files (x86)\Windows Kits\8.0\Include\shared\sdkddkver.h
1> Note: including file: C:\Program Files (x86)\Windows Kits\8.0\Include\um\windows.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\excpt.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h
.
. Some lines later...
.
1> Note: including file: i:\hmcdeliverables\sourcecode\processor\utils.h
1> Note: including file: i:\hmcdeliverables\sourcecode\processor\stdafx.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxwin.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afx.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\new.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxver_.h
1> Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxv_w32.h
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include\afxv_w32.h(16): fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
utils.h
正在该项目的许多文件中使用;但是,我使用警卫
#pragma once
仅处理一次(如果我正确理解的话)。来自“ utils.h”的摘录:
#pragma once
#include "stdafx.h"
#include <string>
#include <opencv2/opencv.hpp>
#include <cstdint>
我的stdafx.h文件:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#ifndef _SECURE_ATL
#define _SECURE_ATL 1
#endif
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
我应该在哪里检查或更改以解决此问题?让我知道是否需要更多信息。