c++ - 为什么 `/usr/include` 不在 gcc 默认搜索路径中

标签 c++ linux gcc

众所周知,gcc在编译目标时会搜索一些默认目录, 我使用 gcc -print-search-dirs 命令并得到这些东西:

install: /usr/lib/gcc/x86_64-redhat-linux/4.8.5/
programs: =/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/bin/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/bin/
libraries: =/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/lib/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/x86_64-redhat-linux/4.8.5/:/lib/../lib64/:/usr/lib/x86_64-redhat-linux/4.8.5/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/lib/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/

我有两个问题:

  1. 什么是 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/bin/意思,为什么要这样写?

  2. 为什么 /usr/include 不在那里?gcc 不需要知道头文件在哪里吗?

最佳答案

关于问题 1,我在 gcc mailing list 中找到了这个:

Note that a/b/c/../../../x will only exist if a/b/c exists.

所以如果 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/<,你的 gcc 只会在 /usr/x86_64-redhat-linux/bin/ 中搜索 存在。

请注意,我在 arch 上有类似的搜索目录,而 /usr/x86_64-redhat-linux/ 不存在,所以我不确定它们为什么甚至包括在内,但 Linux 的目录结构是出了名的不标准化,因此它可能对其他发行版很重要。

关于 2,来自手册页:

-print-search-dirs

      Print the name of the configured installation directory and a list of program and library directories gcc searches---and don't do anything else.

      This is useful when gcc prints the error message installation problem, cannot exec cpp0: No such file or directory.  To resolve this you either need to put cpp0 and the other
       compiler components where gcc expects to find them, or you can set the environment variable GCC_EXEC_PREFIX to the directory where you installed them.  Don't forget the
       trailing /.

这似乎打印的不是库路径,而是 gcc 希望找到它调用的组件的路径。

要查找预处理器搜索的路径,请键入

`gcc -print-prog-name=cc1plus` -v

`gcc -print-prog-name=cc1` -v

用于 C 预处理器。

关于c++ - 为什么 `/usr/include` 不在 gcc 默认搜索路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51990202/

相关文章:

c++ - 如何使用模板别名删除一个不必要的参数

c++ - 如何将第三方库无缝集成到 Visual Studio 2017 中?

c++ - 按引用还是按值传递函数?

json - 在 linux 中使用 jq 解析 JSON 文件

c - 如何以编程方式在正在运行的应用程序中查找符号

python - 错误 : command 'gcc' failed with exit status 1 installing Fatiando (Python Package)

C 编程编译问题

ios - 使用最新的 GCC 进行 iOS 开发以获得 c++11 功能是个好主意吗?

c++ - 如何使用特征库进行 lu 分解 C++

c - 即使 SIGKILLed 但正常进程不会做同样的事情,终端也会与所有 child 一起出现故障