How to add a default include path for GCC in Linux

2018-12-31 19:34发布

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.

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.

5条回答
笑指拈花
2楼-- · 2018-12-31 20:06

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.

查看更多
不流泪的眼
3楼-- · 2018-12-31 20:12

Create an alias for gcc with your favorite includes.

alias mygcc='gcc -I /whatever/'
查看更多
查无此人
4楼-- · 2018-12-31 20:17

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

See here

查看更多
妖精总统
5楼-- · 2018-12-31 20:24

Try setting C_INCLUDE_PATH (for C header files) or CPLUS_INCLUDE_PATH (for C++ header files).

As Ciro mentioned, CPATH will set the path for both C and C++.

More details here.

查看更多
春风洒进眼中
6楼-- · 2018-12-31 20:26

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

查看更多
登录 后发表回答