如何为Linux中的GCC添加默认的路径?

时间:2022-08-29 23:16:17

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.

我希望gcc包含来自$HOME/包含的文件,除了通常包含的目录之外,但是似乎没有一个类似于$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中),我可以在命令行中添加include目录,但是我非常喜欢这里的通用方法,就像在library case中一样。

4 个解决方案

#1


300  

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 * mentioned, CPATH will set the path for both C and C++.

如*所述,CPATH将为C和c++设置路径。

More details here.

更多细节在这里。

#2


39  

Create an alias for gcc with your favorite includes.

为gcc创建一个别名,其中包含您最喜欢的内容。

alias mygcc='gcc -I /whatever/'

#3


34  

Here is link to GCC 4.8.1 manual where C_INCLUDE_PATH and CPLUS_INCLUDE_PATH environment variables are documented.

这里是链接到GCC 4.8.1手册,其中包含C_INCLUDE_PATH和CPLUS_INCLUDE_PATH环境变量。

#4


7  

A gcc spec file can do the job, however all users on the machine will be affected.

gcc规范文件可以完成任务,但是机器上的所有用户都会受到影响。

See here

在这里看到的

#1


300  

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 * mentioned, CPATH will set the path for both C and C++.

如*所述,CPATH将为C和c++设置路径。

More details here.

更多细节在这里。

#2


39  

Create an alias for gcc with your favorite includes.

为gcc创建一个别名,其中包含您最喜欢的内容。

alias mygcc='gcc -I /whatever/'

#3


34  

Here is link to GCC 4.8.1 manual where C_INCLUDE_PATH and CPLUS_INCLUDE_PATH environment variables are documented.

这里是链接到GCC 4.8.1手册,其中包含C_INCLUDE_PATH和CPLUS_INCLUDE_PATH环境变量。

#4


7  

A gcc spec file can do the job, however all users on the machine will be affected.

gcc规范文件可以完成任务,但是机器上的所有用户都会受到影响。

See here

在这里看到的