C++ – Including C++ 11 headers with Clang / LLVM

buildcc++11clangllvm

I have installed clang and llvm from source, and am trying to compile some C++ code using features of the new standard.

I have found that while for example the use of for ranges e.g. for (i : vector) works fine, I am having trouble (cannot find header file) when I need to import a header e.g. <unordered_set> or <tuple>.

Do I need to use the new libc++ to use these headers, or is there just a simple build change I need to make? At the moment I have just built clang and llvm into a folder in my home directory, and am calling clang++ from there.

Best Answer

See http://clang.llvm.org/get_started.html.

If you intend to work on Clang C++ support, you may need to tell it how to find your C++ standard library headers. If Clang cannot find your system libstdc++ headers, please follow these instructions:

  • gcc -v -x c++ /dev/null -fsyntax-only to get the path.

  • Look for the comment "FIXME: temporary hack: hard-coded paths" in clang/lib/Frontend/InitHeaderSearch.cpp and change the lines below to include that path.