visual-studio Visual Studio 不支持包含目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3790632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:29:38  来源:igfitidea点击:

Visual Studio does not honor include directories

visual-studiovisual-studio-2008

提问by Samaursa

I have been in this situation quite a few times where visual studio does not honor the Additional Include Directorieswhen it comes to liband header source files. For example, I just downloaded MyGUI source code and made sure the include directories were correct. I even put them to absolute paths, Visual Studio still complained that it could not find specific header files.

我已经多次遇到这种情况,Visual Studio在涉及和时不尊重附加包含目录。例如,我刚刚下载了 MyGUI 源代码并确保包含目录正确。我什至将它们放在绝对路径中,Visual Studio 仍然抱怨找不到特定的头文件。libheader source files

Does anybody experience the same thing with projects, and if so, is there a solution to this problem?Blockquote

有没有人在项目中遇到过同样的事情,如果有,这个问题有解决方案吗? Blockquote

EDIT:My apologies for not being able to explain fully. I know that the library and source files have different include directories. The project that I received had correct directory paths for the Additional Include Directories and Additional Library Directories but Visual Studio still failed to recognize them properly. I can right click and open the header file within Visual Studio but when compiling it still complains it cannot find the required header files. I regularly make projects relying on a framework I myself programmed, so I am quite familiar with how to set up dependencies. This is however the second time this seems to be happening. I don't recall which 3rd party project I was trying to compile last time, but Visual Studio simply refused to believe that the Additional Include Directoriespaths is where it should look for the header files. I am not sure how to give the complete details of this particular library (MyGUI) but I can point you to the website where you can download it to try and see if it is able to find the header files that are included in the project (if it doesn't compile, that is fine, and it is probably because of additional dependencies, but it should at least be able to find files in the common folder, especially when I put absolute paths in Additional Include Directories)

编辑:我很抱歉无法完全解释。我知道库和源文件有不同的包含目录。我收到的项目具有附加包含目录和附加库目录的正确目录路径,但 Visual Studio 仍然无法正确识别它们。我可以右键单击并在 Visual Studio 中打开头文件,但是在编译时它仍然抱怨找不到所需的头文件。我经常依赖自己编写的框架来制作项目,所以我非常熟悉如何设置依赖项。然而,这似乎是第二次发生。我不记得上次我试图编译哪个 3rd 方项目,但 Visual Studio 只是拒绝相信Additional Include Directories路径是它应该寻找头文件的地方。我不确定如何提供此特定库 (MyGUI) 的完整详细信息,但我可以将您指向可以下载它的网站,以尝试查看它是否能够找到项目中包含的头文件(如果它不编译,那很好,这可能是因为额外的依赖关系,但它至少应该能够在公共文件夹中找到文件,尤其是当我将绝对路径放在附加包含目录中时)

采纳答案by Samaursa

I have found (stumbled) on the solution (I think). It has something to do with the character limit imposed by the OS. Although the limit should be 260, for me it falls in the below 150, see this discussion and links to it. I downloaded and unzipped the file to C:\Users\MyUserName\My Documents\Downloads\Downloads From Chrome\MyGui3.0...[and so on]. I learned quite some time ago not to try to compile projects under such long paths, but this time it completely slipped my mind as VS did not give me a warning at all and pointed me in the wrong direction. Anyway, cutting and pasting the project to D:\fixed the issue. I am not going to checkmark the answer however until someone confirms this.

我发现(偶然发现)解决方案(我认为)。它与操作系统强加的字符限制有关。虽然限制应该是 260,但对我来说它低于 150,请参阅此讨论并链接到它。我将文件下载并解压缩到C:\Users\MyUserName\My Documents\Downloads\Downloads From Chrome\MyGui3.0...[等等]。前段时间我学会了不要尝试在这么长的路径下编译项目,但这一次我完全忘记了,因为 VS 根本没有给我警告并指出我错误的方向。无论如何,剪切和粘贴项目以D:\解决问题。然而,在有人确认这一点之前,我不会勾选答案。

回答by sam

This happened to me once. It turned out the inconsistency of the Debug vs Release builds. When I modified one build, the other build was being compiled. Please set both builds with same include folders and see if it works. Good luck.

这发生在我身上一次。结果证明 Debug 与 Release 版本不一致。当我修改一个构建时,正在编译另一个构建。请使用相同的包含文件夹设置两个版本,看看它是否有效。祝你好运。

回答by Rick

I have the same problem : Can't find .libfile even though I've added the additional include directory.

我有同样的问题:.lib即使我添加了额外的包含目录,也找不到文件。

From an answer of Additional include directory in Visual studio 2015 doesn't work, I tried:

Visual Studio 2015 中附加包含目录不起作用的答案中,我尝试了:

delete the .suofile and restart VS

删除.suo文件并重启VS

Then it works for me.

然后它对我有用。

回答by Adam Wrze?niewski

I had this issue too. Just like sam said - this string value containing path to your framework includes has to be the same for the Debug and Release configurations. So the best way is to choose "Configuration:All Configurations" and "Platform:All Platforms" from the two context checklists on the top of the project properties window before typing it in, or copying from windows explorer adress bar.

我也有这个问题。就像 sam 所说的那样 - 这个包含框架路径的字符串值必须与调试和发布配置相同。所以最好的方法是在输入之前从项目属性窗口顶部的两个上下文清单中选择“配置:所有配置”和“平台:所有平台”,或者从 Windows 资源管理器地址栏中复制。

回答by André Caron

Can you elaborate on this? If I recall, there are at least two places in Visual Studio where you can configure this:

你能详细说明一下吗?如果我记得,Visual Studio 中至少有两个地方可以配置:

  1. Per-installation: Tools/Options/Projects and Solutions/VC++ Directories)
  2. Per-project: Project/Properties/Configuration Properties/"C/C++"/General/Additional Include Directories
  1. 每安装:Tools/Options/Projects and Solutions/VC++ Directories
  2. 每个项目: Project/Properties/Configuration Properties/"C/C++"/General/Additional Include Directories

If you're adding the include directories per-project (#1), which I think you are, and then trying to include from another project, this will obviously not work. Try adding them at the per-installation level and see if it works.

如果您要为每个项目(#1)添加包含目录,我认为您是这样,然后尝试从另一个项目中包含,这显然是行不通的。尝试在每个安装级别添加它们,看看它是否有效。

Also, this may sound stupid/simplistic, but make sure the path is right (i.e. copy-paste into Explorer's path bar and see if the header files are in that folder).

此外,这听起来可能很愚蠢/简单,但请确保路径正确(即复制粘贴到资源管理器的路径栏中并查看头文件是否在该文件夹中)。

回答by Marc Bernier

If by lib files you mean library (.lib) files, the directory location is not specified through C/C++/General/Additional Include Directories but rather through Linker/General/Additional Library Directories.

如果 lib 文件是指库 (.lib) 文件,则目录位置不是通过 C/C++/General/Additional Include Directories 指定的,而是通过 Linker/General/Additional Library Directory 指定的。

It's logical if you think about it. C/C++ options are all compilation options, settings involved with compiling .cpp and .h files. Linker options are all linking options, settings involved with linking up .obj and .lib files.

如果你考虑一下,这是合乎逻辑的。C/C++ 选项都是编译选项,涉及编译 .cpp 和 .h 文件的设置。链接器选项都是链接选项,涉及链接 .obj 和 .lib 文件的设置。

回答by Floris Devreese

I had the same symptoms in my c++ project. Navigating from header to header went fine, but after toggling to the source file of a header (let's say foo.cpp), then the navigation to an #include <bar.cpp>in that source file failed. I got the following error:

我在我的 C++ 项目中有同样的症状。从标题导航到标题很顺利,但是在切换到标题的源文件(比方说foo.cpp)之后,导航到#include <bar.cpp>该源文件中的an失败。我收到以下错误:

File 'bar.cpp' not found in the current source file's directory or in build system paths.

在当前源文件的目录或构建系统路径中找不到文件“bar.cpp”。

After research I noticed that the system build path given in the error where not extended with the include paths of the project. In other words: IntelliSense didn't know that the source file (foo.cpp) was part of the project, and therefore it didn't use the include paths of the project to search for the #include <bar.cpp>.

经过研究,我注意到错误中给出的系统构建路径没有用项目的包含路径扩展。换句话说:IntelliSense 不知道源文件 ( foo.cpp) 是项目的一部分,因此它没有使用项目的包含路径来搜索#include <bar.cpp>.

The fix for me was creating a file intelliSense.cpp(file name doesn't matter) that is part of the project, but excluded from the build. This file contains an include for each source file. ex:

我的修复方法是创建一个文件intelliSense.cpp(文件名无关紧要),它是项目的一部分,但从构建中排除。该文件包含每个源文件的包含。前任:

#include <foo.cpp>
#include <bar.cpp>
...

This way IntelliSense knows that these source files are part of the project, and will therefore use the include paths of the project to resolve the #includesin those source files.

这样 IntelliSense 就知道这些源文件是项目的一部分,因此将使用项目的包含路径来解析#includes这些源文件中的 。

回答by abovady

For me the issue was that .vcxproj Project file was read-onlyand after I added my directory to "Additional directories", the project file did not actually change. I was surprised that VS did not complain about this file being read-only.

对我来说,问题是 .vcxproj 项目文件是只读的,在我将我的目录添加到“其他目录”后,项目文件实际上并没有改变。我很惊讶 VS 没有抱怨这个文件是只读的。

So after I made that file write-able I could compile my project.

因此,在我将该文件设为可写后,我可以编译我的项目。