开发者

Visual C++ Include File not found

I have a project, and I added all the source files to it. I then clicked build, and it said:

fatal error C1083: Cannot open include file: 'common.h': No such file or directory 1> crc64_tablegen.c

This is rather annoying, because common.h is in my project! It's right there! I think it might be in a different directory though. Is the the reason? Should I move everything 开发者_开发技巧to a root directory, then add that instead? Thanx!


Where files are in the project structure makes no difference to the compiler when it is attempting to open include files. If they are in a different directory, you will need to path them appropriately.

That is, if you have this directory structure:

project/include/common.h
project/src/main.cpp

And you have this in your project:

Project
|-> common.h
|-> main.cpp

Your main file will need to do this:

#include "../include/common.h"

And not this:

#include "common.h"

You may, alternatively, define project/include as an Additional Include Directory in your project settings. This will allow you do use the second include form shown above.


Compiler doesn't know anything about project and files included in it. If .h file is in another directory, you need to add this directory to the list. For example, open Project - Properties - C++ - General - Additional Include Directories, and add $(ProjectDir)Include or something like this.


In VC++, the location of files within the project is virtual and has no link whatsoever to the actual filepaths. You may have to be more specific with #include and/or move the source files into the project directory to be found.


Try and add the path in the project settings under Additional Include Directories.

Here are the full set of steps:

  1. Drop down the Tools menu, and select Options
  2. In the box on the left is a list of option categories. Select "Projects and Solutions" and then the sub-category "VC++ Directories"
  3. In the upper right hand corner is a drop-down box that selects a particular set of default directories, including "Executable files", "Include files", "Reference files", "Library files", and "Source files". Generally, you only want to add to the "Include files" or "Library files" lists. Select "Include files"
  4. In the middle of the right hand side of the window is a list of directories. Add the include path by pressing the "New Line" button above the window, or by pressing "Ctrl-Insert". A blank entry appears for you to either type the path or navigate by clicking the "..." button. Generally the final path you want will end with a folder called "include". Enter the path now.
  5. You're done, click OK


If you have added a .h file to an existing project and are getting the error message C1083: cannot open include file. Make sure you have it added properly to the program.

If you have #include it might not work.

Try entering #include "course.h" instead.

I have been working this problem with my project for several hours and have just now realized this error. You can also add the directory in the project properties to have it work, but when you send it to someone else to view it, they might receive the same error.


I just had the same problem in Visual Studio 2017, and found what was causing it. There is a difference between the following two includes:

#include "common.h" // Quoted form
#include <common.h> // Angle-bracket form

First include can uses the file that contains the #include to find the included header file.

Second include ignores the file that contains the #include, so if you don't have the directory of header file in Additional Include Directories it will not be found, ALTHOUGH the IntelliSense will happily jump to the header file (Ctrl+Shift+G) as if it was included like in the first case.

So, either change the #include or add the directory to Additional Include Directories.

More info at Microsoft Docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜