是 Linux 可执行文件“兼容"吗?用 OS X? [英] Is a Linux executable "compatible" with OS X?

查看:24
本文介绍了是 Linux 可执行文件“兼容"吗?用 OS X?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在基于 Linux 的平台上用 C 语言编译程序,然后将其移植到 MacOS 库中,它会起作用吗?

If you compile a program in say, C, on a Linux based platform, then port it to use the MacOS libraries, will it work?

来自编译器的核心机器代码是否在 Mac 和 Linux 上都兼容?

Is the core machine-code that comes from a compiler compatible on both Mac and Linux?

我问这个的原因是因为两者都是基于 UNIX"的,所以我认为这是真的,但我不确定.

The reason I ask this is because both are "UNIX based" so I would think this is true, but I'm not really sure.

推荐答案

不,Linux 和 Mac OS X 二进制文件不能交叉兼容.

No, Linux and Mac OS X binaries are not cross-compatible.

一方面,Linux 可执行文件使用一种名为 ELF 的格式.

For one thing, Linux executables use a format called ELF.

Mac OS X 可执行文件使用 Mach-O 格式.

Mac OS X executables use Mach-O format.

因此,即使很多库通常在每个系统上单独编译,它们也不能以二进制格式移植.

Thus, even if a lot of the libraries ordinarily compile separately on each system, they would not be portable in binary format.

此外,Linux 实际上并非基于 UNIX.它确实与 UNIX 共享了许多共同的特性和工具,但其中很多都与 POSIX 等计算标准有关.

Furthermore, Linux is not actually UNIX-based. It does share a number of common features and tools with UNIX, but a lot of that has to do with computing standards like POSIX.

综上所述,人们可以并且确实创造了非常酷的方法来处理交叉问题- 兼容性.

All this said, people can and do create pretty cool ways to deal with the problem of cross-compatibility.

最后,为了解决您对字节码的看法:在制作二进制文件时,编译器通常会生成 机器码 特定于您正在开发的平台.(情况并非总是如此,但通常如此.)

Finally, to address your point on byte-code: when making a binary, compilers usually generate machine code that is specific to the platform you're developing on. (This isn't always the case, but it usually is.)

这篇关于是 Linux 可执行文件“兼容"吗?用 OS X?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆