[Fixed] fatal error: bits/c++config.h: No such file or directory

Do not miss this exclusive book on Binary Tree Problems. Get it now for free.

In this article, we have explored the reason behind the C++ compilation error "fatal error: bits/c++config.h: No such file or directory" and presented the fix for resolving the error.

Table of contents:

  1. Error: fatal error: bits/c++config.h
  2. Fix 1: Install G++
  3. Fix 2: Use GCC
  4. Fix 3: Add include paths

Error: fatal error: bits/c++config.h

On compiling a C++ code with G++, one may face a compilation error. The compilation command will be as follows:

g++ code.c

The compilation error is as follows:

/usr/include/c++/5/cstring:41:28: fatal error: 
  bits/c++config.h: No such file or directory
compilation terminated.

The issue is with the compiler as it is unable to find the mentioned header file bits/c++config.h which should be available by default.

Fix 1: Install G++

The first fix is to reinstall the multilib version of G++ which should work fine. We shall update the system repository so that the latest G++ version is installed.

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-multilib

To install a specific version of G++ multilib compiler, use the following command:

sudo apt-get install g++-5-multilib

Fix 2: Use GCC

Another fix will be to use a working GCC compiler and enable the flag lstdc++ to compile C++ code with a C compiler. Replace g++ with "gcc -lstdc++".

Replace:

g++ code.c

with

gcc -lstdc++ code.c

Fix 3: Add include paths

Add the following include path in G++ compiler as the header file resides there:

-I/usr/include/c++/5/i486-linux-gnu
-I/usr/include/c++/5/i686-linux-gnu

Check if the header file is available in path using ls command:

ls /usr/include/c++/5/i486-linux-gnu
OR
ls /usr/include/c++/5/i686-linux-gnu

The compilation command will be as follows:

g++ -I/usr/include/c++/5/i486-linux-gnu code.c
OR
g++ -I/usr/include/c++/5/i686-linux-gnu code.c

With this article at OpenGenus, we have resolved the error "fatal error: bits/c++config.h: No such file or directory". Continue your development.

Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.