64位编译的程序可以在32位机器上运行吗?

发布于 2024-08-20 19:26:48 字数 66 浏览 2 评论 0原文

正如标题所说,我在 64 位机器上编译了 C 程序并创建了一个二进制文件。这个二进制文件可以在 32 位机器下工作吗?

As title said, I have C program complied and created a binary in 64-bit machine.Will this binary work under 32-bit ?

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

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

发布评论

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

评论(3

凌乱心跳 2024-08-27 19:26:48

64 位二进制文​​件无法在 32 位操作系统上运行。如果 file 报告 ELF 64-bit,则您拥有 64 位二进制文​​件。

为了在 64 位 Linux 上构建 32 位二进制文​​件,您需要将 -m32 传递给 gcc。您还需要安装 32 位库 (sudo apt-get install libc6-dev-i386)。

64-bit binaries cannot run on a 32-bit OS. If file reports ELF 64-bit, you have a 64-bit binary.

In order to build 32-bit binaries on a 64-bit Linux, you need pass -m32 to gcc. You also need to have 32-bit libraries installed (sudo apt-get install libc6-dev-i386).

你又不是我 2024-08-27 19:26:48

编译机无关紧要。重要的是:生成的代码是 32 位(答案:是)还是 64 位(答案:否)。

The compiling machine does not matter. What matters is: is the code generated 32 bits (answer: yes) or 64 bits (answer: no).

南风几经秋 2024-08-27 19:26:48

它可以在 32 位机器上运行吗?一台不支持 64 位模式的 CPU?不可以。

它可以在 32 位本机操作系统上的 64 位 VM 上运行吗?是的,根据我的经验。

一个令人惊讶的结果是,64 位虚拟机可以在 32 位主机操作系统下运行,前提是 CPU 有能力并且您不想为来宾分配太多内存(> 2G 或左右)。

Will it work on a 32-bit machine? One with a CPU which doesn't support 64-bit mode? No.

Will it work on a 64-bit VM on a 32-bit native OS? Yes, in my experience.

A surprising result is that 64-bit VMs CAN be run under a 32-bit host OS, provided the CPU is capable and you don't want to allocate too much ram (>2G or thereabouts) to the guest.

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