-1

POSIX was developed so that we can have software compatibility (portability) with variants of Unix:

The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems.1 POSIX defines both the system- and user-level application programming interfaces (API), along with command line shells and utility interfaces, for software compatibility (portability) with variants of Unix and other operating systems.1 POSIX is also a trademark of the IEEE.1 POSIX is intended to be used by both application and system developers.2

macOS and Linux are both POSIX-compliant. So supposedly, an application written for macOS should run on Linux.

But according to this question, there is a binary incompatibility between macOS and Linux. According to the chosen best answer, it is because you need to link appropriate libraries, but it was objected by a commenter saying that the real issue is incompatible system calls.

So if there is a binary incompatibility between macOS and Linux, then what is the sense of complying with POSIX? This makes POSIX useless, doesn't it?

Noob_Guy
  • 203
  • Windows 11 for Intel and Windows 11 for ARM are also binary incompatible. According to your logic, that makes Windows useless. Also, Linux for AMD64 and Linux for ARM are binary incompatible. According to your logic, that makes Linux useless. Also, macOS for Intel and macOS for ARM are binary incompatible. By your logic, that makes macOS useless. – Jörg W Mittag Aug 30 '22 at 20:12

1 Answers1

5

The key is in this part of your quote:

POSIX defines both the system- and user-level application programming interfaces (API)

Application programming interfaces define what interfaces can be relied on when programming applications. It means that you can write a program following POSIX, and you will be able to build it on any POSIX-compliant system (if you’ve only used POSIX features).

POSIX doesn’t concern itself with the application binary interfaces, which is what matters when running a given binary.

So you can take the source code to a program which only uses POSIX APIs, and build it on macOS, and POSIX-compliant Linux systems, and run the resulting binary. You can’t take a macOS binary and run it on Linux, at least not without some translation program (like Wine for Windows programs).

On top of that, many programs use more than the POSIX APIs, so you’d have to ensure everything else they need is also available on the target system (this is where libraries come in).

Stephen Kitt
  • 434,908
  • is interface same as function? – Noob_Guy Aug 31 '22 at 07:42
  • The "interface" is how the user application source code gets to use the specific feature: its function name, the number and type of args, the return type and allowed values, and the definition of any visible extended data types such as structs. The underlying library or OS can do whatever it likes under the hood, as long as it complies with the POSIX specification. I don't see the word function anywhere in your question, so I am unclear what the context is here: in my mind, a function is any piece of code with defined inputs and outputs, whether in user code, library, or OS. – Paul_Pedant Aug 31 '22 at 08:54
  • I mean "method" rather, like "sum()", "sort()", "print()", etc. So basically, "interface" = "method"? – Noob_Guy Aug 31 '22 at 10:07
  • No, interfaces are general descriptions of how to interact with a “system” across a boundary. Functions/methods can be part of an interface, and in the case of POSIX System Interfaces, they are; but they aren’t all of an interface. POSIX itself is an interface description (POSIX stands for Portable Operating System Interface). – Stephen Kitt Aug 31 '22 at 10:17
  • @Noob_Guy: For a really obvious example of an interface on a computer that is not a method, think of the IEC socket on the power supply. It defines the interface between the power cable and the PSU, but it is very much not a method or function. An interface simply defines how two different components interact with each other. It doesn't need to have a specific implementation, e.g. a method or a function or a header file. Anything where you have a well-defined interaction between components, you have an interface. – Jörg W Mittag Sep 01 '22 at 04:56
  • That sounds like a "protocol", doesn't it? So interface = protocol? – Noob_Guy Sep 03 '22 at 13:51
  • A protocol is one form of interface definition, yes, but interfaces don’t have to be protocols. – Stephen Kitt Sep 05 '22 at 13:15