I am running the 32bit version of Ubuntu 10.10 and trying to cross compile to a 64 bit target. Based on my research, I have installed the g++-multilib package.
The program is a very simple hello world:
#include <iostream>
int main( int argc, char** argv )
{
std::cout << "hello world" << std::endl;
return 0;
}
Compile:
g++ -m64 main.cpp
Error:
In file included from main.cpp:1:
/usr/include/c++/4.4/iostream:39: fatal error: bits/c++config.h: No such file or directory
compilation terminated.
I have found a c++config.h
file but they reside under the i486-linux-gnu
and i686-linux-gnu
directories in /usr/include/c++/4.4/
There is not c++config.h
in /usr/include/c++/bits
.
Any ideas on what I am missing? Compiling without the -m64
flag works fine (a.out is created and runs correctly).
Edit Thanks to the hint from @nightcracker, I did a little more investigation into the include structure on the 32 and 64 bit systems. I have added an answer below that "fixes" the problem temporarily but I think it will break on the next update. Basically, I am missing a directory called /usr/include/c++/4.4/i686-linux-gnu/64
that should contain a subdirectory called bits
that has the missing include file. Any idea what package should be taking care of this?
Did you try adding
-I/usr/include/c++/4.4/i486-linux-gnu
or-I/usr/include/c++/4.4/i686-linux-gnu
?This bug is fixed in "gcc-4.6".
https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/793411
Seems to be a typo error in that package of gcc. The solution:
While compiling in RHEL 6.2 (x86_64), I installed both 32bit and 64bit libstdc++-dev packages, but I had the "c++config.h no such file or directory" problem.
Resolution:
The directory
/usr/include/c++/4.4.6/x86_64-redhat-linux
was missing.I did the following:
I'm now able to compile 32bit binaries on a 64bit OS.
On my 64 bit system I noticed that the following directory existed:
It would then make sense that on my 32 bit system that had been setup for 64bit cross compiling there should be a corresponding directory like:
I double checked and this directory did not exist. Running
g++
with the verbose parameter showed that the compiler was actually looking for something in this location:The error regarding the
ignoring nonexistent directory
was the clue. Unfortunately, I still don't know what package I need to install to have this directory show up so I just copied the/usr/include/c++/4.4/x86_64-linux-gnu/bits
directory from my 64 bit machine to/usr/include/c++/4.4/i686-linux-gnu/64/bits
on my 32 machine.Now compiling with just the
-m64
works correctly. The major drawback is that this is still not the correct way to do things and I am guessing the next time Update Manager installs and update to g++ things may break.Adding this answer partially because it fixed my problem of the same issue and so I can bookmark this question myself.
I was able to fix it by doing the following:
If you've installed a version of
gcc
/g++
that doesn't ship by default (such asg++-4.8
on lucid) you'll want to match the version as well: