缺少包含“bits/c”“config.h”在Ubuntu 32位上交叉编译64位程序时

发布于 2024-10-11 07:42:37 字数 1197 浏览 0 评论 0原文

我正在运行 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 和 < /usr/include/c++/4.4/ 中的 code>i686-linux-gnu 目录 / 中没有 c++config.h usr/include/c++/bits

对我所缺少的有什么想法吗?不使用 -m64 标志进行编译可以正常工作(a.out 已创建并正确运行)。

编辑 感谢 @nightcracker 的提示,我对 32 位和 64 位系统上的包含结构进行了更多调查。我添加了 下面的答案暂时“解决”了问题,但我认为它会在下次更新时崩溃。基本上,我缺少一个名为 /usr/include/c++/4.4/i686-linux-gnu/64 的目录,该目录应包含一个名为 bits 的子目录,该子目录缺少包含内容文件。知道应该用什么包来处理这个问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

寄人书 2024-10-18 07:42:37

添加此答案的部分原因是它解决了我同一问题的问题,因此我可以自己为这个问题添加书签。

我可以通过执行以下操作来修复它:

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

如果您安装了默认情况下不提供的 gcc / g++ 版本(例如 g++ -4.8 on lucid)你也想匹配版本:

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

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:

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

If you've installed a version of gcc / g++ that doesn't ship by default (such as g++-4.8 on lucid) you'll want to match the version as well:

sudo apt-get install gcc-4.8-multilib g++-4.8-multilib
肥爪爪 2024-10-18 07:42:37

您是否尝试添加 -I/usr/include/c++/4.4/i486-linux-gnu 或 -I/usr/include/c++/4.4/i686-linux-gnu

Did you try adding -I/usr/include/c++/4.4/i486-linux-gnu or -I/usr/include/c++/4.4/i686-linux-gnu?

你げ笑在眉眼 2024-10-18 07:42:37

在 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 位操作系统上编译 32 位二进制文​​件。

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:

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

I'm now able to compile 32bit binaries on a 64bit OS.

终陌 2024-10-18 07:42:37

似乎是 gcc 那个包中的拼写错误。解决办法:

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

Seems to be a typo error in that package of gcc. The solution:

mv /usr/include/c++/4.x/i486-linux-gnu /usr/include/c++/4.x/i686-linux-gnu/64
生死何惧 2024-10-18 07:42:37

基本上它用于 HeapOverflows 或其他反转类型问题,即如果您想将 64 位 ELF 更改为 32 位 ELF 并且在转换时显示错误。

您只需运行

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

将更新您的库的 命令
套餐升级:

将安装以下附加软件包:
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
推荐套餐:
lib32stdc++6-8-dbg libx32stdc++6-8-dbg glibc-doc
将安装以下新软件包:
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

类似于此将显示在您的终端上

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

只是一片海 2024-10-18 07:42:37

在我的 64 位系统上,我注意到存在以下目录:

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

然后,在为 64 位交叉编译设置的 32 位系统上,应该有一个相应的目录,例如:

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

我仔细检查,该目录不存在。使用 verbose 参数运行 g++ 表明编译器实际上是在这个位置寻找某些东西:

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.

关于ignoring nonexistent directory 的错误就是线索。不幸的是,我仍然不知道需要安装什么软件包才能显示此目录,因此我只是从以下位置复制了 /usr/include/c++/4.4/x86_64-linux-gnu/bits 目录我的 64 位机器到我的 32 机器上的 /usr/include/c++/4.4/i686-linux-gnu/64/bits

现在仅使用 -m64 即可正常编译。主要缺点是,这仍然不是正确的处理方式,我猜测下次更新管理器安装并更新到 g++ 时,事情可能会中断。

On my 64 bit system I noticed that the following directory existed:

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

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:

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

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:

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.

坦然微笑 2024-10-18 07:42:37

根据我的经验,sudo apt-get install gcc-multilib g++-multilib 有帮助。但我的另一个问题是我忘记清理目录,所以我仍然遇到相同的错误。第一次使用clang或者cmake。所以我只要删除原来的目录并重新编译就可以了。希望它能帮助像我这样的人。

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.

薄情伤 2024-10-18 07:42:37

在 x86 机器上针对arm32进行交叉编译时遇到了同样的问题,如果您要针对arm进行交叉编译,请确保您已经安装了最新的libstdc++ pkg。

sudo apt install libstdc++-10-dev-armhf-cross

然后您可能会遇到另一个标头错误,即找不到“asm/errno.h”文件。只需为此安装 gcc-multilib 即可。

sudo apt install gcc-multilib

Ran into the same problem while cross-compiling on x86 machine for arm32, if you are cross-compiling then for arm then make sure you have installed the latest libstdc++ pkg.

sudo apt install libstdc++-10-dev-armhf-cross

Then you may run into another header error which is 'asm/errno.h' file not found. Just install gcc-multilib for this.

sudo apt install gcc-multilib
多情出卖 2024-10-18 07:42:37

就我而言,这只是一个路径问题。我减少了源文件的路径长度并且它起作用了......

In my case, it only has been a path issue. I reduced the path length of my source files and it worked...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文