On a OS X Mavericks system, clang-modernize can't find #include files


After watching Chandler Carruth’s http://channel9.msdn.com/Events/GoingNative/2013/The-Care-and-Feeding-of-C-s-Dragons I decided to try the format and modernize examples in the middle of his presentation. After installing the latest LLVM suite, all examples without #include files work fine, both in clang-format and clang-modernize. Very impressive.

Using the native (Apple, Xcode) toolchain, I can cmake, make and run the example programs in a build directory directly under the source directory, e,g. clang-tools/vector/build under clang-tools/vector which contains vector.cpp and CMakeLists.txt.

But clang-modernize will fail if it contains a template based #include, e.g. Chandler’s loop-convert example based on a small vector loop.
Somehow I can’t figure out how to specify the right flags for the compiler/linker in cmakelist.txt.

Any pointers appreciated!


Rob J. Goedman



int sum(const std::vector &numbers) {
int result = 0;
for (std::vector::const_iterator it = numbers.begin();
it != numbers.end(); ++it) {
result += *it;
return result;

int main() {
std::vector nums = { 1, 5, 6, 38 };
std::cout << sum(nums) << std::endl;


cmake_minimum_required(VERSION 2.8)

include_directories($ENV{GMOCK_HOME}/include $ENV{GMOCK_HOME}/gtest/include)
link_directories($ENV{GMOCK_HOME}/mybuild $ENV{GMOCK_HOME}/gtest/mybuild)
add_definitions(-stdlib=libc++ -std=c++11)


add_executable(test ${sources})
target_link_libraries(test pthread)
target_link_libraries(test gmock)
target_link_libraries(test gtest)

On OS X Maverick, libc++ headers are part of the compiler toolchain and not of the system. That's why when using a custom toolchain (or clang based tool), you got this error.

To use libc++ with your own clang build, you have to install it alongside your clang binary.

The good news is that it will be automatically done when installing clang if you checkout the libc++ project at the right place, that is in <llvm sources>/projects/libcxx

cd <llvm sources>/projects
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx

Now, go to your build directory and run make install again.

It should install the clang tools and libc++ headers at the right place, and clang should find them.

Note that if you want to know where clang look for the libc++ headers, you can pass the "-v" flags to the compiler to tell it to print the header search path.

Works great Jean-Daniel! Thanks a lot!


Rob J. Goedman