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

发布于 2024-07-29 06:57:08 字数 505 浏览 3 评论 0原文

因此,当我们执行以下操作时:

#include <stdio.h>

与编译器相比

#include "myFile.h"

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

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

好多鱼好多余 2024-08-05 06:57:08

请参阅此处: 搜索路径

摘要:

#include <stdio.h>

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

#include "myFile.h"

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

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

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

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

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.

不气馁 2024-08-05 06:57:08

gcc 是一个丰富而复杂的“编排”程序,它调用许多其他程序来履行其职责。 为了查看 #include "goo"#include 将在您的系统上搜索的具体位置,我建议:

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

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

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.

暮凉 2024-08-05 06:57:08

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

请注意,某些具有大量标头的库会将它们安装到子目录中,例如/usr/include/openssl。 要包含其中之一,只需提供不带 /usr/include 部分的路径,例如:

#include <openssl/aes.h>

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>
開玄 2024-08-05 06:57:08

gcc 的 #include 文件存储在 /usr/include 中。
g++的标准包含文件存储在/usr/include/c++中。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文