Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emulating Linux binaries under Mac OS X

How do I run Linux binaries under Mac OS X?

Googling around I found a couple of emulators but none for running Linux binaries on a Mac. There are quite a few posts about running Mac OS X on Linux and that kind of stuff - but that's the opposite of what I want to do.

Update:

Thanks for all the answers! I am fully aware of MacPorts and Fink or any of the other things; and no, I do not want any of these utilities, and I do not want any of the package managers, I prefer to compile things myself. I also have Parallels and could set up virtual machines and all that jazz...

The only thing I want to do is to find a way to run a binary that I do not have the source code for and has been compiled for Linux, but I do not want to run it under Linux but under Mac OS X. Therefore my question about emulators.

like image 450
flouxgoux Avatar asked Dec 23 '09 17:12

flouxgoux


People also ask

Can Linux binaries run on macOS?

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.

Can you run Linux files on a Mac?

Whether you need a customizable operating system or a better environment for software development, you can get it by dual booting Linux on your Mac. Linux is incredibly versatile (it's used to run everything from smartphones to supercomputers), and you can install it on your MacBook Pro, iMac, or even your Mac mini.

How do I emulate Linux on Mac?

Here is how to install Linux on Mac using the Parallels Desktop software: Download a set of Linux virtual machines from the main installation Assistant Menu. Choose your preferred Linux distribution and download it. Once downloaded, you can install and begin running Linux on your Mac.

Does Mac use ELF binaries?

Among those formats listed, the ones in most common use are PE (on Microsoft Windows), ELF (on Linux and most other versions of Unix), Mach-O (on macOS and iOS) and MZ (on DOS).


1 Answers

Well there is a project introducing something like Linux's binfmt_misc to OS X so now what you need is an ELF loader, a dynamic linker that can load both Mach-O and ELF, and some mechanism to translate Linux calls to OS X ones.

Just for inspiration, you can implement the dynamic linker in the fashion that it ignores filename extension - both libfoo.so.1 (as an Linux ELF) and libfoo.1.dylib (as an Mach-O) can be loaded so that OS X versions of system libraries can be reused so that you do not need to write a "hosted on OS X" libc.so and syscalls can be handled by an kext that translates Linux calls to OS X ones in kernel.

Or, in an more elegant way, implement a stripped down Linux kernel as a kext that makes the OS X kernel a dual-purpose. However that will require you to use two sets of libraries. (Binaries do not clash so it is largely okay)

like image 200
Maxthon Chan Avatar answered Oct 05 '22 14:10

Maxthon Chan