是Linux可执行"兼容"与OS X? [英] Is a Linux executable "compatible" with OS X?
问题描述
如果您编译说,C程序,基于Linux的平台上,然后将它移植到使用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?
时的核心机器code来自编译器在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.
编辑:
最后,以解决您的字节级code点:做一个二进制时,编译器通常会产生的机code 特定于您正在开发的平台。 (这并非总是如此,但它通常是)。
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屋!