[SATLUG] include paths

Bruce Dubbs bruce.dubbs at gmail.com
Sun Jun 15 12:01:36 CDT 2014


Borries Demeler wrote:
> Can anyone tell me where the default include paths on a
> regular unix system are defined?
>
> I.e., where are these paths set:
>
>       /usr/local/include
>       libdir/gcc/target/version/include
>       /usr/target/include
>       /usr/include
>
> so that gcc can find them.
>
> Also: If I include a file like this:
>
> #include <file.h>
>
> The assumption is that the file can be found in the include
> path that has been set in the environment.
>
> So what if I have a subdirectory in /usr/include, say "sys", do I have set
> this manually in my search path (i.e., #include <sys/file.h> or can unix
> find it automatically? I see many subdirectories under /usr/include but
> it is not clear if their contents are automatically supposed to be found.

It's built into gcc.

$ echo 'main(){}' > dummy.c
$ gcc dummy.c -v 2>&1 | grep -B10 'search list'

#include "..." search starts here:
#include <...> search starts here:
  /opt/xorg/include
  /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/include
  /usr/local/include
  /usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/include-fixed
  /usr/include
End of search list.

It can be adjusted with CPATH, C_INCLUDE_PATH, and CPLUS_INCLUDE_PATH.

In my case, I have

CPLUS_INCLUDE_PATH=/opt/xorg/include
C_INCLUDE_PATH=/opt/xorg/include

https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Environment-Variables.html#Environment-Variables

   -- Bruce


More information about the SATLUG mailing list