简体   繁体   中英

Visual Studio 2012: C++ compiler ignoring user-specified include directories

I have the common error fatal error C1083: Cannot open include file: 'afxres.h': No such file or directory . Search engines show up lots of hits for this, but none of the suggested solutions work for me.

Normally this would appear to be a problem with the paths. So, I ensured the relevant libraries were installed, and located the file. Using the absolute path as the #include works fine:

#include "C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\atlmfc\\include\\afxres.h"

But, if I add the directory (C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\atlmfc\\include) to the project settings (or to Microsoft.Cpp.Win32.User property sheet), and try this line:

#include "afxres.h"

I get the error C1083 again. Yet Visual Studio clearly can find the file - if I right-click on the filename and select "Open Document 'afxres.h'" then it opens it immediately!

Why would Visual Studio be ignoring the #include path that I specified? Other #include paths I've included in a similar way work perfectly.

目录明确包含在构建设置中

but I did have Visual C++ 2010 Express on here previously, from which it seems to have imported some settings

That was the essential comment. Express doesn't support ATL and MFC. What's still missing is that you only got this problem on projects that you started on VS2010 previously.

Do note that adding the path like you did in the project property sheet was not necessary. Visible in the screen-shot, it is already covered by the $(VCInstallDir)atlmfc\\include entry in the inherited properties. So the conclusion to draw is that the $(VCInstallDir) macro value is wrong.

Short from an install mishap or a whacked registry, this can happen when you converted a project that you previously started in VS2010. Switch back from the Property Manager to the Solution Explorer window, right-click your project, Properties, General page. Change the "Platform Toolset" setting from v100 to v110. You'll now use the VS2012 include directories instead of the VS2010 Express ones.

Beware that changes to the Microsoft.Cpp.Win32.User project property sheet will affect all your projects, you'll want to reset it back.

First, ensure that MFC is enabled in project properties > Configuration Properties > General

use of mfc must be set to static or dynamic library.

secondly, to ensure that cl.exe is using all of the include directories that you specify, you need to go to project properties > c/c++ > general and change suppress startup banner to no /nologo-

this will give you the full cl command for each source file, showing exactly what visual studio is attempting to do with the code and configuration options that you give to it.

eg. cl /c /ZI /nologo- /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yc"StdAfx.h" /Fp"Debug\\test.pch" /Fo"Debug\\\\" /Fd"Debug\\vc100.pdb" /Gd /TP /showIncludes /analyze- /errorReport:prompt stdafx.cpp

If it is using your extra include folders, you should see a lot of extra -I switches in the command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM