clang says "cstdlib file not found"

Tarnay Kálmán picture Tarnay Kálmán · Jul 27, 2011 · Viewed 14.5k times · Source

On an almost default install of Ubuntu 11.04 I installed clang.

I am trying to compile this:

#include <cstdlib>
int main(){
  return 0;
}

g++ can deal with it just fine, but clang++ errors out: fatal error: 'cstdlib' file not found

Can someone explain why this happens? and what needs to be done to make this work? I expected clang++ to be a drop-on replacement for g++.

Answer

Marcus Borkenhagen picture Marcus Borkenhagen · Jul 27, 2011

Seems like your clang build is not searching the correct platform include paths. Try checking with

clang -v ...

where it is looking for headers (and check that your platform include paths are there). You might have to add additional include directories (e.g. /usr/include/c++/x.y).

You might want to take a look at the source file lib/Frontend/InitHeaderSearch.cpp, The method AddDefaultCPlusPlusIncludePaths does some distribution/gcc-version specific magic (I had to fix it for my own system once).