Coder Perfect

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 regular include directories, but $LD LIBRARY PATH doesn’t appear to have an equivalent.

I know I can just add the include directory to the command line when compiling (or in the makefile), but I’d prefer a more universal solution, similar to how the library ca

Asked by Jesse Beder

Solution #1

Set C INCLUDE PATH if you’re using C header files, or CPLUS INCLUDE PATH if you’re using C++ header files.

CPATH will set the path for both C and C++, as Ciro indicated (and any other language).

More information can be found in the GCC documentation.

Answered by jcrossley3

Solution #2

Make a gcc alias using your chosen included.

alias mygcc='gcc -I /whatever/'

Answered by dirkgently

Solution #3

Just to clarify, CPLUS INCLUDE PATH and C INCLUDE PATH are not the same as LD LIBRARY PATH; LD LIBRARY PATH serves the ld (the dynamic linker at runtime), whereas LIBRARY PATH serves your C/C++ compiler with library location information.

Answered by Dagim Sisay

Solution #4

A gcc spec file can do the job, but it will affect all users on the machine.


Answered by dimba

Post is based on