Linux 找出 GCC 包含的路径是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17939930/
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
Finding out what the GCC include path is
提问by rwallace
I'm trying to programmatically find the #include
path on Linux, which as I understand it, in practice means finding what GCC considers it to be. (Is that quite true? How does Clang do it?)
我正在尝试以编程方式#include
在 Linux 上找到路径,据我所知,这实际上意味着找到 GCC 认为它是什么。(这是真的吗?Clang 是如何做到的?)
According to http://gcc.gnu.org/onlinedocs/cpp/Search-Path.htmlsome of the components involve the CPU architecture and the GCC version; the latter in particular seems tricky; I suppose it could be obtained by running gcc --version
and parsing the output (or gcc -v
), but this seems inelegant at best and fragile at worst. Doing it from within one's code assuming one's program is being compiled with GCC might be another option, but it would require depending on that assumption.
根据http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html 的一些组件涉及 CPU 架构和 GCC 版本;尤其是后者似乎很棘手;我想它可以通过运行gcc --version
和解析输出(或gcc -v
)来获得,但这在最好的情况下似乎不优雅,在最坏的情况下似乎很脆弱。假设一个人的程序是用 GCC 编译的,从一个人的代码中执行它可能是另一种选择,但它需要取决于该假设。
What's the recommended way to do it?
推荐的方法是什么?
采纳答案by caf
The command
命令
echo | gcc -E -Wp,-v -
will show the include path in use.
将显示正在使用的包含路径。
回答by devnull
I'm not sure what you mean by the recommendedway to find the include path. The standardway is as given below (for c and c++):
我不确定您所说的查找包含路径的推荐方法是什么意思。的标准方法是下面所给出(对于C和C ++):
$ `gcc -print-prog-name=cc1` -v
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
/usr/include
End of search list.
^C
$ `gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.7
/usr/include/c++/4.7/x86_64-linux-gnu
/usr/include/c++/4.7/backward
/usr/lib/gcc/x86_64-linux-gnu/4.7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
/usr/include
End of search list.
^C