Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including C++ 11 headers with Clang / LLVM

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.

like image 470
zenna Avatar asked Apr 06 '12 18:04

zenna


2 Answers

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.

like image 199
Johannes Schaub - litb Avatar answered Sep 20 '22 09:09

Johannes Schaub - litb


While the standard library comes with distributions of your compiler, when you're building it yourself, you still need to build the standard library itself. Some of its components may be header-only, but not all of them are.

So you do need to at least download the library, if not build it. Clang can use GCC's libstdc++, but they also have their libc++ project.

like image 45
Nicol Bolas Avatar answered Sep 18 '22 09:09

Nicol Bolas