为什么"/usr/include"不在 GCC 默认搜索路径中
why `/usr/include` is not in gcc default search path
众所周知,gcc 在编译目标时会搜索一些默认的 dir, 我使用gcc -print-search-dirs
commnd 并得到这些东西:
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邮件列表中找到了这个:
请注意,a/b/c/../../../x 仅在 a/b/c 存在时才存在。
因此,您的 gcc 只会在/usr/x86_64-redhat-linux/bin/
中搜索/usr/lib/gcc/x86_64-redhat-linux/4.8.5/
如果存在。
请注意,我在 arch 上有类似的搜索目录,而/usr/x86_64-redhat-linux/
等效的搜索目录不存在,所以我不确定为什么它们甚至被包括在内,但 Linux 有一个臭名昭著的非标准化目录结构,所以也许它对其他发行版很重要。
关于 2,从手册页:
-打印搜索目录
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++中搜索嵌套多映射值
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 二进制搜索树叶数问题
- 为什么二进制搜索在我的测试中不起作用
- 正在尝试重载二进制搜索树分配运算符
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 向量上的线性搜索
- 如何在动态数组上使用搜索函数
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- cmake:添加要搜索头文件的目录
- 使用C++创建特殊的二叉搜索树
- 在C++的字符串中搜索和删除某些字符
- std::unordered_map 搜索算法是如何实现的?
- 使用不变量来确定二分搜索中的边界条件
- 二叉搜索如何比线性搜索更快?
- 按边长度递归搜索图中所有可行路径
- QStackWidget - 按名称搜索
- 在递归二叉搜索树中搜索
- 我的二进制搜索程序只是关闭了