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

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

Where are include files stored - Ubuntu Linux, GCC

linuxgcclocationinclude

提问by Frank 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.

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

I thinkthat 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?

认为在我的 Ubuntu Linux 机器上,文件存储在/usr/include/. 编译器如何知道去哪里寻找这些文件?这是可配置的还是只是预期的默认值?我会在哪里寻找这个配置?

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.

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

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

我一直认为它们随编译器一起提供的,但这是一个假设......

采纳答案by Karl Voigtland

See here: Search Path

请参阅此处: 搜索路径

Summary:

概括:

#include <stdio.h>

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

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

#include "myFile.h"

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

当包括文件是在引号在当前目录中的预处理器首先搜索,然后通过指定的路径-iquote,然后-I路径,则标准路径。

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

-nostdinc可用于完全阻止预处理器搜索标准路径。

Environment variablescan also be used to add search paths.

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

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

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

回答by Meredith L. Patterson

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 libfoopackage 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.

Karl 回答了您的搜索路径问题,但就“文件来源”而言,需要注意的一件事是,如果您安装了该libfoo软件包并希望对其进行一些开发(即,使用其标头),您还需要安装libfoo-dev. /usr/include如您所见,标准库头文件已经在 中。

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/includepart, for example:

请注意,一些带有很多头文件的库会将它们安装到子目录中,例如/usr/include/openssl. 要包含其中之一,只需提供没有该/usr/include部分的路径,例如:

#include <openssl/aes.h>

回答by Alex Martelli

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:

gcc 是一个丰富而复杂的“编排”程序,它调用许多其他程序来执行其职责。为了查看系统上的搜索位置#include "goo"#include <zap>搜索位置的特定目的,我建议:

$ 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.

这是查看包含文件的搜索列表的一种方法,包括(如果有)#include "..."将查看但#include <...>不会查看的目录。我显示的这个特定列表实际上是在 Mac OS X(又名 Darwin)上,但我推荐的命令将向您显示搜索列表(以及我在...此处替换的有趣配置细节;-)在任何系统上gcc 运行正常。

回答by Manish Bhadani

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

\#includegcc的文件存储在/usr/include. g++ 的标准包含文件存储在/usr/include/c++.