Software⏱️ 3 min read📅 2026-06-03

How to Fix: Missing include "bits/c++config.h" when cross compiling 64 bit program on 32 bit in Ubuntu

Fix missing include bits/c++config.h when cross compiling 64 bit program on 32 bit in Ubuntu

Quick Answer: Use -m32 flag instead of -m64 for correct cross-compilation

The error 'bits/c++config.h: No such file or directory' occurs when attempting to cross-compile a 64-bit program on a 32-bit system. This issue affects users who are compiling 64-bit programs using the g++ compiler on a 32-bit Ubuntu installation.

This error can be frustrating because it prevents the compilation process from completing successfully, resulting in a failed build and wasted time. In this guide, we will walk you through the steps to resolve this issue.

💡 Why You Are Getting This Error

  • The primary reason for this error is that the cross-compiler is unable to locate the 'bits/c++config.h' file, which is specific to 64-bit systems. This file provides configuration settings and macros necessary for building 64-bit programs.
  • An alternative reason could be related to the multilib environment setup on the 32-bit system. The g++-multilib package may not have been properly configured or installed correctly.

🛠️ Step-by-Step Verified Fixes

Using the -m32 flag with g++

  1. Step 1: Open a terminal and navigate to the directory where your source code is located.
  2. Step 2: Run the command `g++ -m32 -o output main.cpp` (assuming this is the name of your executable). This will instruct the compiler to use the 32-bit ABI instead of the 64-bit ABI.
  3. Step 3: Verify that the compilation was successful by checking the output file. If it exists, then the issue has been resolved.

Using the --target option with g++

  1. Step 1: Run the command `g++ -m64 --target=x86-32 main.cpp` (assuming this is the name of your executable). This will instruct the compiler to generate code for a 32-bit target system.
  2. Step 2: Verify that the compilation was successful by checking the output file. If it exists, then the issue has been resolved.

🎯 Final Words

To summarize, the 'bits/c++config.h: No such file or directory' error can be resolved by using the -m32 flag with g++ or specifying the --target option to generate code for a 32-bit target system. By following these steps, you should be able to successfully compile your 64-bit program on a 32-bit Ubuntu installation.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions