how to add include paths to clang globally

34.9k views Asked by At

I know this one way of adding include paths to clang:- clang++ -I <dir> a.cpp

but with this, that path is only added for that particular file, and u have to write that every time linting, so how can I add some include paths globally to clint.

1

There are 1 answers

2
Artyer On BEST ANSWER

There are also some environment variables which Clang looks at for include paths. For c++, they would be CPATH (both C and C++) and CPLUS_INCLUDE_PATH (C++ only) (And LIBRARY_PATH for the linker). So you can add something like this to your shell startup file if you are using bash or similar:

export CPLUS_INCLUDE_PATH="${CPLUS_INCLUDE_PATH:+${CPLUS_INCLUDE_PATH}:}<dir>"

And you could also just alias clang++ with clang++ -I<dir>.