一. VS项目中的包含目录、库目录、附加包含目录、附加库目录、附加依赖项
VC++包含目录和库目录
C++附加包含目录
Link 附加库目录和附加依赖项
---------------------------------------------------------------------------------------------------------------------------------------------------
Include directories: “VC++ Directories -> Include Directories” : 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.
Note: 针对全局,solution 下面的所有project
----------------------------------------------------------------------------------------------------------------------------------------------------
Additional Include Directories”: The directory to be added to the list of directories searched for include files.
The compiler searches for directories in the following order:
1.Directories containing the source file.
2.Directories specified with the /I option, in the order that CL encounters them.
3.Directories specified in the INCLUDE environment variable.
Note:只针对当前的project
其中 order2中的/I是由C/C++ -> General -> Additional Include Directories设置的。
而在 order3中的INCLUDE是由VC++ Directories -> Include Directories设置的。
---------------------------------------------------------------------------------------------------------------------------------------------------
Additional Library Directories: Linker -> General -> Additional Library Directories
---------------------------------------------------------------------------------------------------------------------------------------------------
Additional Dependicies:准确的指出你要包含那些 .lib files 。
Example from MSDN
The following command looks for the include files requested by MAIN.c in the following order: First, if specified by using double-quotes, local files are searched. Next, search continues in the \INCLUDE directory, then in the \MY\INCLUDE directory, and finally in the directories assigned to the INCLUDE environment variable.
CL /I \INCLUDE /I\MY\INCLUDE MAIN.C
--------------------------------------------------------------------------------------------------------------------------------------------------------
在visual stuudio 的C++一般的设置如下:
In C++, you got the header files (.h), the (.lib) files and the (.dll) files.
In Visual Studio, you provide the location to search for these files in three different places:
Configuration Properties => C/C++ => General => Additional Include directories. Here you list out the "include" directories that you want searched and made available.
Configuration Properties => Linker => General => Additional Library directories. Here you list out the "lib" directories that you want to be searched and made available.
Configuration Properties => Linker => Input => Additional dependencies. Here you explicitly specify the .lib files that want to include.
二. 包含文件查找顺序
当被include的文件路径不是绝对路径的时候,有不同的搜索顺序。对于使用双引号“”包含的include文件,搜索的时候按以下顺序:
1.在包含当前include指令的文件所在的文件夹内搜索;
2.如果上一步找不到,则在之前已经使用include指令打开过的文件所在的文件夹内搜索,如果已经有多个被include的文件,则按照它们被打开的相反顺序 去搜索;
3.如果上一步找不到,则在编译器设置的include路径内搜索;
4.如果上一步找不到,则在系统的INCLUDE环境变量内搜索。
而对于使用半角尖括号<>包含的include文件,搜索的时候按以下顺序:
1.在编译器设置的include路径内搜索;
2.如果是在命令行中编译,则在系统的INCLUDE环境变量内搜索。
对于非绝对路径的文件使用上述两种include指令搜索时,一旦找到include命令所指定的文件,编译器就停止搜索。但是如果被include的文件是绝对路径的文件,比如 #include "D:\Program Files\OpenCV1.0\cv\include\cv.h" ,被包含的cv.h文件路径是绝对路径,这种情况下编译器直接按照这个给出的绝对路径是搜索。
参考:https://blog.csdn.net/theonegis/article/details/42913255
https://blog.csdn.net/godenlove007/article/details/7531521
https://docs.microsoft.com/en-us/cpp/build/reference/i-additional-include-directories?view=vs-2017