22

There is no file called bits/c++config.h in the c++ include directory which is required by the cstring header file. But when I include the the header cstring and compile with g++, it does not give me error. The problem occurred when I tried to compile the program with clang++ compiler in the following way.

$clang++ -cc1 -I/usr/include -I/usr/include/c++/4.6.1 -I/usr/lib/gcc/i686-linux-gnu/4.6.1 -I/usr/include/i386-linux-gnu -I opt_149739_build/include hello.cpp

In file included from /media/space/hello.cpp:2:
In file included from /media/space/opt_149739_build/include/clang/Driver/Driver.h:13:
In file included from /media/space/opt_149739_build/include/clang/Basic/Diagnostic.h:17:
In file included from /media/space/opt_149739_build/include/clang/Basic/DiagnosticIDs.h:18:
In file included from /media/space/opt_149739_build/include/llvm/ADT/StringRef.h:14:
/usr/include/c++/4.6.1/cstring:42:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>

I am using g++ 4.6.1 on Ubuntu 11.04

What went wrong?

Moshe
  • 9,283
  • 4
  • 29
  • 38
A. K.
  • 34,395
  • 15
  • 52
  • 89
  • could provides more details, like for instance : which version of gcc do you use ? on which OS ? and what is your gcc command line ? – Coren Feb 08 '12 at 22:27

3 Answers3

33

The file bits/c++config.h is the platform specific include relative to the current compiler, so it is hidden in another directory, searched by default by g++, but not by clang++, as it seems.

In my machine, running locate c++config.h gives the following (relevant) files:

/usr/include/c++/4.6/i686-linux-gnu/64/bits/c++config.h
/usr/include/c++/4.6/i686-linux-gnu/bits/c++config.h

The first one is for 64-bits and the second one for 32-bits.

So just add -I/usr/include/c++/4.6/i686-linux-gnu or -I/usr/include/c++/4.6/i686-linux-gnu/64 or whatever you need for your platform.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • yes i found out it is there in the same directory what you got. thanks – A. K. Feb 09 '12 at 08:41
  • 2
    If you don't have the appropriate c++config.h for your architecture, install libstdc++-devel from your repository. – Brien Coffield Jul 02 '13 at 16:08
  • in some cases this might not be enough: sometimes you need -I/usr/include/c++/4.6/i686-linux-gnu/c++/4.6 I use -I/usr/include/i386-linux-gnu/c++/4.7/ for my machine and 4.7 version of gcc and it all works – Eugene B Jul 15 '13 at 10:57
1

Ran into the same problem while cross-compiling, the problem was solved after installing libstdc++-10-dev for arm. If you are not cross-compiling then you can try installing latest libstdc++ pkg.

sudo apt-get update
sudo apt-get install libstdc++-10

Then you may run into a header error: ' asm/errno.h' file not found. Just install gcc-multilib for this.

sudo apt install gcc-multilib
0

It can be related to how clang++ search its headers files.

You'll find a sample patch of how they fix it for fedora 15, 4 months ago, here.

See this red hat bugzilla post for more info.

Gabriel Southern
  • 9,602
  • 12
  • 56
  • 95
Coren
  • 5,517
  • 1
  • 21
  • 34
  • While installing clang I did edit the Frontend/InitHeaderSearch.cpp file to include the required directories to address the problem. Still I got this error. For now, I have added all the required paths in my CMakeLists.txt to address this issue. – A. K. Feb 09 '12 at 09:09