Visual Studio can't 'see' my included

2020-02-10 00:09发布

I created an empty 'Demo' project in Visual Studio 2008 and added some existing projects to my solution. Included "MyHeader.h" (other project's header) in main.cpp file which is in 'Demo'. Also added header files' path in "Tools/Option/VC++ Directories/Include files" section. But intellisense says: "File 'MyHeader.h' not found in current source file's directory or in build system paths..."

How the problem can be fixed? Thanks.

9条回答
\"骚年 ilove
2楼-- · 2020-02-10 00:24

In my experience, with VS2010, when include files can't be found at compile time, doing a clean, then build usually fixes the problem. It's not that rare for the editor to be able to open an include file and then the compiler to announce that it can't find that very file, even when it is open on the screen!

查看更多
家丑人穷心不美
3楼-- · 2020-02-10 00:26

If you choose Project and then All Files in the menu, all files should be displayed in the Solution Explorer that are physically in your project map, but not (yet) included in your project. If you right click on the file you want to add in the Solution Explorer, you can include it.

查看更多
Root(大扎)
4楼-- · 2020-02-10 00:26

This happened to me just now, after shutting down and restarting the computer. Eventually I realised that the architecture had somehow been changed to ARM from x64.

查看更多
\"骚年 ilove
5楼-- · 2020-02-10 00:35

I know this is an older question, but none of the above answers worked for me. In my case, the issue turned out to be that I had absolute include paths but without drive letters. Compilation was fine, but Visual Studio couldn't find an include file when I right-clicked and tried to open it. Adding the drive letters to my include paths corrected the problem.

I would never recommend hard-coding drive letters in any aspect of your project files; either use relative paths, macros, environment variables, or some mix of the tree for any permanent situation. However, in this case, I'm working in some temporary projects where absolute paths were necessary in the short term. Not being able to right-click to open the files was extremely frustrating, and hopefully this will help others.

查看更多
啃猪蹄的小仙女
6楼-- · 2020-02-10 00:40

Try adding the header file to your project's files. (right click on project -> add existing file).

查看更多
Root(大扎)
7楼-- · 2020-02-10 00:41

Delete the .sdf file that is in your solution directory. It's just the Intellisense database, and Visual Studio will recreate it the next time you open that solution. This db can get corrupted and cause the IDE to not be able to find things, and since the compiler generates this information for itself on the fly, it wouldn't be affected.

查看更多
登录 后发表回答