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

所以,当我们做下面这些事情的时候:

#include <stdio.h>

VS

#include "myFile.h"

在我的例子中,编译器 GCC 知道 stdio.h (甚至目标文件)在我的硬盘上的位置。它只是利用文件,没有我的互动。

在我的 Ubuntu Linux 机器上,文件存储在 /usr/include/编译器如何知道在哪里查找这些文件?是可配置的还是只是预期的默认值?我在哪里可以找到这种配置?

既然我问了一个关于这些包含文件的问题,那么这些文件的来源是什么?我知道这在 Linux 社区中可能是模糊的,但是谁来管理这些呢?为 Windows 编译器提供和管理相同文件的用户。

我一直以为他们用编译器编译 ,但那只是一个假设..。

234103 次浏览

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.

Karl answered your search-path question, but as far as the "source of the files" goes, one thing to be aware of is that if you install the libfoo package and want to do some development with it (i.e., use its headers), you will also need to install libfoo-dev. The standard library header files are already in /usr/include, as you saw.

Note that some libraries with a lot of headers will install them to a subdirectory, e.g., /usr/include/openssl. To include one of those, just provide the path without the /usr/include part, for example:

#include <openssl/aes.h>

gcc is a rich and complex "orchestrating" program that calls many other programs to perform its duties. For the specific purpose of seeing where #include "goo" and #include <zap> will search on your system, I recommend:

$ touch a.c
$ gcc -v -E a.c
...
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i686-apple-darwin9/4.0.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
# 1 "a.c"

This is one way to see the search lists for included files, including (if any) directories into which #include "..." will look but #include <...> won't. This specific list I'm showing is actually on Mac OS X (aka Darwin) but the commands I recommend will show you the search lists (as well as interesting configuration details that I've replaced with ... here;-) on any system on which gcc runs properly.

The \#include files of gcc are stored in /usr/include . The standard include files of g++ are stored in /usr/include/c++.