c++clanginclude-path

How to add include paths to clang globally


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 you have to write that every time linting, so how can I add some include paths globally to clint.


Solution

  • 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>.