Sunday, January 9, 2011

Cross compiling 64 bit program on 32 bit machine (Ubuntu 10.10)

In preparation for creating a small build cluster for helping with compiling Chromium I was trying to get my old college laptop up and running under Ubuntu 10.10. I installed the g++-multilib package as multiple sources on the internet had instructed but when I tried compiling 64 bit hello world I got the following 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.
Searching through /usr/include yielded a couple instances of bits/c++config.h but they were all located under different architectures (i486-linux-gnu, i686-linux-gnu).

Googling around did not result in much so I decided to ask the fine folks over at Stackoverflow (link to question is at bottom of page - if you read it now, this post will be significantly less interesting). One answer told me to explicitly include the path for the c++config.h file from the other architectures - this worked but it seemed a bit hacky to have to explicitly set include paths for system includes.

I had not used the verbose parameter for g++ before so I thought I would give it a try to see if that could explain a little more what the system was trying to do:
jesse@shalored:~/projects/test$ g++ -v -m64 main.cpp
Using built-in specs.
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
COLLECT_GCC_OPTIONS='-v' '-m64' '-shared-libgcc' '-mtune=generic'
/usr/lib/gcc/i686-linux-gnu/4.4.5/cc1plus -quiet -v -imultilib 64 -D_GNU_SOURCE main.cpp -D_FORTIFY_SOURCE=2 -quiet -dumpbase main.cpp -m64 -mtune=generic -auxbase main -version -fstack-protector -o /tmp/ccMvIfFH.s
ignoring nonexistent directory "/usr/include/c++/4.4/i686-linux-gnu/64"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../i686-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.4
/usr/include/c++/4.4/backward
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.4.5/include
/usr/lib/gcc/i686-linux-gnu/4.4.5/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.4.4-14ubuntu5) version 4.4.5 (i686-linux-gnu)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 3.0.0-p3.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128197
Compiler executable checksum: 1fe36891f4a5f71e4a498e712867261c
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.
The ignoring nonexistent directory error messages was what gave me the clue. Since it was looking for /usr/include/c++/4.4/i686-linux-gnu/64, I checked my 64 machine hoping to see a similiar structure but with an x86_64 architecture and corresponding 32bit directory. Sure enough it was there: /usr/include/c++/4.4/x86_64-linux-gnu/32/bits. To fix my problem 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 I know this is not a proper solution since the next update to the system could break something but I think it was enough to get going. Now on to getting this system to help out with building!

Stackoverflow Question: Missing include “bits/c++config.h” when cross compiling 64 bit program on 32 bit in Ubuntu

1 comment:

  1. Hi Jesse,
    Compiling with verbose switch on was a great tip, you saved me a lot of time.

    Thanks!

    ReplyDelete