如何在 Linux 中为 GCC 添加默认包含路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/558803/
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
How to add a default include path for GCC in Linux?
提问by Jesse Beder
I'd like gcc to include files from $HOME/include
in addition to the usual include directories, but there doesn't seem to be an analogue to $LD_LIBRARY_PATH
.
$HOME/include
除了通常的包含目录之外,我还希望 gcc 包含文件,但似乎没有类似于$LD_LIBRARY_PATH
.
I know I can just add the include directory at command line when compiling (or in the makefile), but I'd really like a universal approach here, as in the library case.
我知道我可以在编译时(或在 makefile 中)在命令行中添加包含目录,但我真的很喜欢这里的通用方法,就像在库案例中一样。
采纳答案by jcrossley3
Try setting C_INCLUDE_PATH
(for C header files) or CPLUS_INCLUDE_PATH
(for C++ header files).
尝试设置C_INCLUDE_PATH
(对于 C 头文件)或CPLUS_INCLUDE_PATH
(对于 C++ 头文件)。
As Ciro mentioned, CPATH
will set the path for both C and C++ (and any other language).
正如 Ciro 所提到的,CPATH
将为 C 和 C++(以及任何其他语言)设置路径。
More details in GCC's documentation.
GCC 文档中的更多详细信息。
回答by dirkgently
Create an alias for gcc with your favorite includes.
使用您最喜欢的包含为 gcc 创建一个别名。
alias mygcc='gcc -I /whatever/'
回答by dimba
回答by Dagim Sisay
just a note: CPLUS_INCLUDE_PATH
and C_INCLUDE_PATH
are not the equivalent of LD_LIBRARY_PATH
.
LD_LIBRARY_PATH
serves the ld
(the dynamic linker at runtime) whereas the equivalent of the former two that serves your C/C++ compiler with the location of libraries is LIBRARY_PATH
.
只是一个注意事项:CPLUS_INCLUDE_PATH
并且C_INCLUDE_PATH
不等同于LD_LIBRARY_PATH
.
LD_LIBRARY_PATH
为ld
(运行时的动态链接器)提供服务,而前两个为您的 C/C++ 编译器提供库位置的等价物是LIBRARY_PATH
.