众所周知,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/
我有两个问题:
什么是
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/bin/
意思,为什么要这样写?为什么
/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/