Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a default include path for GCC in Linux?

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.

like image 769
Jesse Beder Avatar asked Feb 17 '09 21:02

Jesse Beder


People also ask

How do I change the include path?

Expand C/C++ General and select Paths and Symbols. Click here to see an illustration (displayed in a separate window). Click Add to define new element (Include Path, Symbol, Library path etc). Click Edit to change selected element (Include Path, Symbol, Library path etc).

How do I find the GCC path?

You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.

Which option of GCC adds include directory of header files?

gcc -I adds include directory of header files.

What is the include path?

includePath An include path is a folder that contains header files (such as #include "myHeaderFile. h" ) that are included in a source file. Specify a list of paths for the IntelliSense engine to use while searching for included header files.


2 Answers

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++ (and any other language).

More details in GCC's documentation.

like image 59
jcrossley3 Avatar answered Oct 24 '22 08:10

jcrossley3


Create an alias for gcc with your favorite includes.

alias mygcc='gcc -I /whatever/' 
like image 28
dirkgently Avatar answered Oct 24 '22 07:10

dirkgently