Is a Linux executable “compatible” with OS X?

前端 未结 5 1153
孤城傲影
孤城傲影 2020-11-29 08:08

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

Is the core machine-code that comes from a comp

5条回答
  •  天命终不由人
    2020-11-29 09:02

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

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

    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.

    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.

    EDIT:

    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.)

提交回复
热议问题