include包含文件查找的顺序 .
2012-11-21 20:47
225 查看
从microsoft网站上找到关于#include Directive (C/C++)的相关问题解释如下:
The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears.
按照上述,二者的区别在于:当被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文件路径是绝对路径,这种情况下编译器直接按照这个给出的绝对路径是搜索。
以下为一个使用尖括号<>include的例子:
#include <stdio.h>
在这个例子里,我们向源程序代码中包含stdio.h文件,由于使用的是尖括号<>,预处理器搜索的时候,先在编译器设置的include路径内搜索,如果找不到,就在系统的INCLUDE环境变量内搜索。
以下为一个使用双引号" "include的例子:
from:http://blog.csdn.net/godenlove007/article/details/7531521
The #include directive tells the preprocessor to treat the contents of a specified file as if those contents had appeared in the source program at the point where the directive appears.
Syntax Form | Action |
---|---|
Quoted form | The preprocessor searches for include files in the following order: In the same directory as the file that contains the #include statement. In the directories of any previously opened include files in the reverse order in which they were opened. The search starts from the directory of the include file that was opened last and continues through the directory of the include file that was opened first. Along the path specified by each /I compiler option. Along the paths specified by the INCLUDE environment variable. |
Angle-bracket form | The preprocessor searches for include files in the following order: Along the path specified by each /I compiler option. When compiling from the command line, along the paths that are specified by the INCLUDE environment variable. |
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文件路径是绝对路径,这种情况下编译器直接按照这个给出的绝对路径是搜索。
以下为一个使用尖括号<>include的例子:
#include <stdio.h>
在这个例子里,我们向源程序代码中包含stdio.h文件,由于使用的是尖括号<>,预处理器搜索的时候,先在编译器设置的include路径内搜索,如果找不到,就在系统的INCLUDE环境变量内搜索。
以下为一个使用双引号" "include的例子:
#include "defs.h"
在这个例子里,我们向源程序代码中包含defs.h文件,由于使用的是双引号" ",预处理器搜索的时候,使用了这条指令的父文件所在文件夹内搜索,所谓的父文件,就是这条include指令所在的文件,如果找不到,在父文件的父文件所在文件夹内搜索,如果仍然找不到,则在编译器设置的include路径内搜索,如果还找不到,就在系统的INCLUDE环境变量内搜索。
from:http://blog.csdn.net/godenlove007/article/details/7531521
相关文章推荐
- include包含文件查找的顺序
- include包含文件查找的顺序
- include包含文件查找的顺序
- include包含文件查找的顺序
- include包含文件查找的顺序
- php中include包含文件路径查找过程
- atal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h
- linux下查找某目录下所有文件包含某字符串的命令
- 文件包含include的三种形式的控制指令
- VC++全局包含文件路径设置( Include 设置)
- Linux 查找包含某个字符串的文件
- 用 find 命令在指定文件类型中查找包含指定文字的文件
- fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h
- HTML文件中也玩include文件包含
- Layout布局文件中通过include来包含其他布局文件
- C/C++头文件包含顺序注意事项
- C++中头文件中是包含include还是包含类的前置声明
- 在所有文件中查找包含某字符串的文件
- HTML文件中也玩include文件包含
- 给定包含4300000000个32位整数的顺序文件,如何找出一个出现至少两次的整数