64位编译的程序可以在32位机器上运行吗?
正如标题所说,我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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
reportsELF 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
).编译机无关紧要。重要的是:生成的代码是 32 位(答案:是)还是 64 位(答案:否)。
The compiling machine does not matter. What matters is: is the code generated 32 bits (answer: yes) or 64 bits (answer: no).
它可以在 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.