C++ “包含目录”和“其他包含目录”有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6883276/
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-08-28 20:49:27  来源:igfitidea点击:

What is the difference between "Include Directories" and "Additional Include Directories"

c++visual-studio-2010visual-studiocompilation

提问by Artium

In configuration properties of my project, under the "VC++ directories" there is an entry for "Include Directories". But under "C/C++" option, there is another entry called "Additional Include Directories". Same thing happens with library directories.

在我的项目的配置属性中,在“VC++ 目录”下有一个“包含目录”条目。但是在“C/C++”选项下,还有一个条目叫做“Additional Include Directories”。库目录也会发生同样的事情。

What are the difference between these two entries?

这两个条目有什么区别?

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

采纳答案by Hans Passant

This is awkwardness that got introduced in VS2010. The VC++ Directories settings used to be located in Tools + Options, Projects and Solutions, VC++ Directories. Global settings that applied to every project that was built on the machine. It is still there but points out that you should now change it in your project settings. A side-effect of the build engine overhaul in VS2010, enabling building with msbuild. Removing the per-project settings would have been logical but that would break too many existing projects.

这是 VS2010 中引入的尴尬。VC++ 目录设置过去位于工具 + 选项、项目和解决方案、VC++ 目录中。应用于机器上构建的每个项目的全局设置。它仍然存在,但指出您现在应该在项目设置中更改它。VS2010 中构建引擎大修的副作用,支持使用 msbuild 进行构建。删除每个项目的设置是合乎逻辑的,但这会破坏太多现有的项目。

As such, it is probably best to treat the VC++ Directories settings as the machine default. It is automatically preset by the VS installer. Tinker with it only if you need an unusual directory search order, putting the custom locations last. Very unusual to do so.

因此,最好将 VC++ 目录设置视为机器默认设置。它由 VS 安装程序自动预设。仅当您需要不寻常的目录搜索顺序时才修改它,将自定义位置放在最后。这样做很不寻常。

It does work however. And it did get taken advantage of eventually. Empowering the Platform Toolset setting in VS2012 and up. Different compiler, different linker, different #include directories, different linker search path. Modified with just one setting, nice.

然而它确实有效。它最终确实被利用了。在 VS2012 及更高版本中增强平台工具集设置。不同的编译器,不同的链接器,不同的#include 目录,不同的链接器搜索路径。只修改了一个设置,不错。

回答by CodeNaked

The Include Directoriescorresponds to the environment variable INCLUDE.

包含目录对应于环境变量INCLUDE

Directory settings displayed in the window are the directories that Visual Studio will search for include files referred to in your source code files. Corresponds to environment variable INCLUDE.

窗口中显示的目录设置是 Visual Studio 将搜索源代码文件中引用的包含文件的目录。对应于环境变量 INCLUDE。

While the Additional Include Directoriesare passed via a command line argument (i.e. the \Ioption).

附加包含目录是通过命令行参数(即\I选项)传递的。

回答by Pressacco

CONFIGURING INCLUDE PATHS

配置包含路径

VC++ Directories: Include Directories

VC++ 目录:包含目录

  • this value is inherited from the INCLUDEWindowsenvironment variable which is defined outside of Visual Studio
    • environment variables can be: global to the computer or have user level scope
    • The INCLUDEand LIBenvironment variables are created when the Microsoft Windows SDKis installed with Visual Studio.
  • 此值继承自在Visual Studio外部定义的INCLUDEWindows环境变量
    • 环境变量可以是:全局到计算机或具有用户级别范围
    • INCLUDELIB当创建环境变量的Microsoft Windows SDK安装有Visual Studio中

C/C++: Additional Include Directories

C/C++:附加包含目录

  • is a project level setting... you will have to define this value for every project in your solution
  • this value can be persisted to source control
  • 是项目级别设置...您必须为解决方案中的每个项目定义此值
  • 这个值可以持久化到源代码控制

ADDITIONAL NOTES

补充说明

Which one should I use?

我应该使用哪一种?

The decision to use Include Directoriesor Additional Include Directorieswill depend on your organization's development process. In my opinion, it is more important:

使用包含目录附加包含目录的决定将取决于您组织的开发过程。在我看来,更重要的是:

  • that you are able to consistently and reliably re-create the development environment (think: handing off source code to another developer)
  • for developers within an organization use a consistent approach
  • 您能够始终如一地可靠地重新创建开发环境(想想:将源代码交给另一个开发人员)
  • 对于组织内的开发人员使用一致的方法

A Note About Macros

关于宏的说明

  • The C++ project configuration macros(not to be confused with C++ pre-processor #definedirective) inherit content from different sources. Macros like...
    • $(Include)inherit their values from Windowsenvironment variables
    • $(OutDir)inherit their values from Visual StudioIDE
  • C++ 项目配置(不要与 C++ 预处理器#define指令混淆)从不同来源继承内容。宏之类的...
    • $(Include)Windows环境变量继承它们的值
    • $(OutDir)Visual StudioIDE继承它们的值

REFERENCES

参考