1

我正在尝试构建和运行一个旧的(并且非常大(大约 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

我应该在哪里检查或更改以解决此问题?如果需要更多信息,请告诉我。

4

0 回答 0