Is a Linux executable “compatible” with OS X?

前端 未结 5 1160
孤城傲影
孤城傲影 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:07

    In general you can easily port a program across various Unix brands. However you need (at least) to recompile it on each platform.

    Executables (binaries) are not usable on several platforms, because an executable is tightly coupled with the operating system's ABI (Application Binary Interface), i.e. the conventions of how an application communicates with the operating system.

    For instance if your program prints a string onto the console using the POSIX write call, the ABI specifies:

    • How a system call is done (Linux used to call the 0x80 software interrupt on x86, now it uses the specific sysenter instruction)
    • The system call number
    • How are the function's arguments transmitted to the system
    • Any kind of alignment
    • ...

    And this varies a lot across operating systems.

    Note however that in some cases there may be “ABI adapters” allowing to run binaries of one OS onto another OS. For instance Wine allows you to run Windows executables on various Unix flavors, NDISwrapper allows you to use Windows network drivers on Linux.

提交回复
热议问题