IT박스

Ubuntu에서 32 비트에서 64 비트 프로그램을 크로스 컴파일 할 때 "bits / c ++ config.h"가 누락되었습니다.

itboxs 2020. 5. 31. 21:10
반응형

Ubuntu에서 32 비트에서 64 비트 프로그램을 크로스 컴파일 할 때 "bits / c ++ config.h"가 누락되었습니다.


32 비트 버전의 Ubuntu 10.10을 실행 중이며 64 비트 대상으로 크로스 컴파일하려고합니다. 내 연구에 따라 g ++-multilib 패키지를 설치했습니다.

이 프로그램은 매우 간단한 hello world입니다.

#include <iostream>

int main( int argc, char** argv )
{
  std::cout << "hello world" << std::endl;
  return 0;
}

엮다:

g++ -m64 main.cpp

오류:

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.

c++config.h파일 을 찾았 지만 i486-linux-gnu및에 i686-linux-gnu디렉토리가 /usr/include/c++/4.4/있습니다 . c++config.h/usr/include/c++/bits있습니다.

내가 잃어버린 것에 대한 아이디어가 있습니까? -m64플래그 없이 컴파일하면 제대로 작동합니다 (a.out이 만들어지고 올바르게 실행 됨).

편집 @nightcracker의 힌트 덕분에 32 및 64 비트 시스템의 include 구조에 대해 조금 더 조사했습니다. 아래에 문제를 일시적으로 "수정" 하는 답변 을 추가 했지만 다음 업데이트에서 문제가 발생한다고 생각합니다. 기본적으로 포함 파일이없는 /usr/include/c++/4.4/i686-linux-gnu/64하위 디렉토리를 포함 해야하는 디렉토리 bits가 누락되었습니다. 어떤 패키지가 이것을 처리해야하는지 아십니까?


이 문제를 부분적으로 추가하면 동일한 문제에 대한 내 문제가 해결 되었으므로이 질문에 직접 북마크 할 수 있습니다.

다음을 수행하여 문제를 해결할 수있었습니다.

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

기본적으로 제공되지 않는 gcc/ 버전 g++(예 : g++-4.8lucid)을 설치 한 경우 버전도 일치 시키려고합니다.

sudo apt-get install gcc-4.8-multilib g++-4.8-multilib

-I/usr/include/c++/4.4/i486-linux-gnu또는을 추가하려고 했습니까 -I/usr/include/c++/4.4/i686-linux-gnu?


RHEL 6.2 (x86_64)에서 컴파일하는 동안 32 비트 및 64 비트 libstdc ++-dev 패키지를 모두 설치했지만 "c ++ config.h 해당 파일 또는 디렉토리가 없습니다 "문제가 발생했습니다.

해결:

디렉토리 /usr/include/c++/4.4.6/x86_64-redhat-linux가 없습니다.

나는 다음을 수행했다.

cd /usr/include/c++/4.4.6/
mkdir x86_64-redhat-linux
cd x86_64-redhat-linux
ln -s ../i686-redhat-linux 32

이제 64 비트 OS에서 32 비트 바이너리를 컴파일 할 수 있습니다.


해당 gcc 패키지에서 오타가 발생한 것 같습니다. 해결책:

mv /usr/include/c++/4.x/i486-linux-gnu /usr/include/c++/4.x/i686-linux-gnu/64

내 64 비트 시스템에서 다음 디렉토리가 있음을 알았습니다.

/usr/include/c++/4.4/x86_64-linux-gnu/32/bits

그런 다음 64 비트 크로스 컴파일을 위해 설정된 32 비트 시스템에는 다음과 같은 해당 디렉토리가 있어야합니다.

/usr/include/c++/4.4/i686-linux-gnu/64/bits

나는 두 번 확인 했고이 디렉토리는 존재하지 않았다. g++verbose 매개 변수로 실행 하면 컴파일러가 실제로이 위치에서 무언가를 찾고 있음을 보여줍니다.

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 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.


This bug is fixed in "gcc-4.6".

https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/793411


Basically It is used in HeapOverflows or other reversing type Problems i.e. If you want to change a 64 bit ELF to 32 bit ELF and it is showing error while converting.

You can simply run the commands

apt-get install gcc-multilib g++-multilib

which will update your libraries Packages upgraded:

The following additional packages will be installed: g++-8-multilib gcc-8-multilib lib32asan5 lib32atomic1 lib32gcc-8-dev lib32gomp1 lib32itm1 lib32mpx2 lib32quadmath0 lib32stdc++-8-dev lib32ubsan1 libc-dev-bin libc6 libc6-dbg libc6-dev libc6-dev-i386 libc6-dev-x32 libc6-i386 libc6-x32 libx32asan5 libx32atomic1 libx32gcc-8-dev libx32gcc1 libx32gomp1 libx32itm1 libx32quadmath0 libx32stdc++-8-dev libx32stdc++6 libx32ubsan1 Suggested packages: lib32stdc++6-8-dbg libx32stdc++6-8-dbg glibc-doc The following NEW packages will be installed: g++-8-multilib g++-multilib gcc-8-multilib gcc-multilib lib32asan5 lib32atomic1 lib32gcc-8-dev lib32gomp1 lib32itm1 lib32mpx2 lib32quadmath0 lib32stdc++-8-dev lib32ubsan1 libc6-dev-i386 libc6-dev-x32 libc6-x32 libx32asan5 libx32atomic1 libx32gcc-8-dev libx32gcc1 libx32gomp1 libx32itm1 libx32quadmath0 libx32stdc++-8-dev libx32stdc++6 libx32ubsan1

similar to this will be shown to your terminal


From my experience, sudo apt-get install gcc-multilib g++-multilib helps. But my another issue is that I FORGET to clean the directory so I still get the same error. It is the first time to use clang or cmake. So I just delete my original directory and re-compile and it works. Hope it helps someone like me.

참고URL : https://stackoverflow.com/questions/4643197/missing-include-bits-cconfig-h-when-cross-compiling-64-bit-program-on-32-bit

반응형