16 Feb'15

Clang fatal error: standard headers not found

In the morning I decided to try building the json11 library. I almost submitted a github issue but then understood that the error quite silly and was probably originating from my broken setup:

$ make test
clang++ -O -std=c++11 -stdlib=libc++ json11.cpp test.cpp -o test -fno-rtti -fno-exceptions
In file included from json11.cpp:22:
./json11.hpp:53:10: fatal error: 'string' file not found
#include <string>
         ^
1 error generated.
test.cpp:1:10: fatal error: 'string' file not found
#include <string>
         ^
1 error generated.

As you might see, string is a part of the standard library.

Let’s see what clang is on my system:

$ clang --version
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix

Surprisingly enough, the solution was found in the StackOverflow comment:

sudo apt-get install libc++-dev

While fighting this issue I found some package management commands useful:

  • apt-get remove doesn’t always remove an existing library. apt-get purge solves it.
  • In order to see all package names installed that match a pattern, run dpkg -l | grep "^rc" | awk ‘{print $2}’ | grep clang.
  • You can pipe the output of the previous command directly to xargs sudo apt-get purge -y.
  • If you can’t get anything to work to remove a package, use sudo dpkg —purge —force-all clang. Warning: it will break your system if previous commands warned you. Run sudo apt-get install -f to fix packages afterwards, but be sure you know what you’re doing.

Comments