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

LinuxGccIncludeEnvironment Variables

Linux Problem Overview


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.

Linux Solutions


Solution 1 - Linux

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.

Solution 2 - Linux

Create an alias for gcc with your favorite includes.

alias mygcc='gcc -I /whatever/'

Solution 3 - Linux

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.

Solution 4 - Linux

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

See HOWTO Use the GCC specs file

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJesse BederView Question on Stackoverflow
Solution 1 - Linuxjcrossley3View Answer on Stackoverflow
Solution 2 - LinuxdirkgentlyView Answer on Stackoverflow
Solution 3 - LinuxDagim SisayView Answer on Stackoverflow
Solution 4 - LinuxdimbaView Answer on Stackoverflow