Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a Linux executable "compatible" with OS X?

Tags:

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 compiler compatible on both Mac and Linux?

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

like image 969
bgroenks Avatar asked Feb 24 '12 23:02

bgroenks


People also ask

Why can't macOS apps run on Linux?

Why OSX applications won't run natively on linux: First of all OSX uses a different binary format than Linux, so Linux can't execute binaries compiled for OSX (the same way it can't execute binaries compiled for Windows or BSD).

Is Linux different from macOS?

Linux is an open source operating system whereas Windows OS is commercial. Linux has access to source code and alters the code as per user need whereas Windows does not have access to the source code. In Linux, the user has access to the source code of the kernel and alter the code according to his need.

Why is OS X better than Linux?

Unlike Linux, which is rarely running on hardware that it was meant to be paired with, macOS is always running on hardware that was built for it. Nearly every component inside of a Mac computer was designed and built by Apple. And the OS running on that hardware was also built by Apple.

What UNIX Linux version is Mac OS X based upon?

The first desktop version, Mac OS X 10.0, was released in March 2001, with its first update, 10.1, arriving later that year. All releases from Mac OS X 10.5 Leopard and after are UNIX 03 certified, with an exception for OS X 10.7 Lion. Apple's mobile operating system, iOS, has been considered a variant of macOS.


1 Answers

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.

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

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

like image 116
Tom Avatar answered Nov 13 '22 09:11

Tom