Я пытаюсь собрать и запустить старый (и довольно большой (около 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
Где я должен проверить или изменить, чтобы решить эту проблему?Дайте мне знать, если потребуется дополнительная информация.