且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在哪里包含存储的文件 - Ubuntu Linux,GCC

更新时间:2023-11-29 22:02:28

请参阅: Search Path b $ b

  #include 

当包含文件位于括号中时,预处理器首先在通过 -I 标志。然后它搜索标准的包含路径(请参阅上面的链接,并使用 -v 标志在您的系统上测试)。

  #includemyFile.h

当include文件在引号预处理器首先在当前目录中搜索,然后搜索由 -iquote -I 路径和标准路径指定的路径。



-nostdinc 可用于防止预处理器根本搜索标准路径。

环境变量也可用于添加搜索路径。



如果使用 -v 标志进行编译,则可以看到使用的搜索路径。


So, when we do the following:

#include <stdio.h>

versus

#include "myFile.h"

the compiler, GCC in my case, knows where that stdio.h (and even the object file) are located on my hard drive. It just utilizes the files with no interaction from me.

I think that on my Ubuntu Linux machine the files are stored at /usr/include/. How does the compiler know where to look for these files? Is this configurable or is this just the expected default? Where would I look for this configuration?

Since I'm asking a question on these include files, what are the source of the files? I know this might be fuzzy in the Linux community but who manages these? Who would provide and manage the same files for a Windows compiler.

I was always under the impression that they come with the compiler but that was an assumption...

See here: Search Path

Summary:

#include <stdio.h>

When the include file is in brackets the preprocessor first searches in paths specified via the -I flag. Then it searches the standard include paths (see the above link, and use the -v flag to test on your system).

#include "myFile.h"

When the include file is in quotes the preprocessor first searches in the current directory, then paths specified by -iquote, then -I paths, then the standard paths.

-nostdinc can be used to prevent the preprocessor from searching the standard paths at all.

Environment variables can also be used to add search paths.

When compiling if you use the -v flag you can see the search paths used.