Is it true that most of the times source code for Linux programs can be compiled into Mac OS programs and vice versa?

  • Mac OS is POSIX compliant, Linux effectively as well. So if a program was written carefully to conform to POSIX, it is source-portable. However, that is rarely the case, as it's easy to accidentally use platform-specific APIs. – amon Mar 1 '17 at 8:36

The world of source code is so large that "most" is a hopelessly vague qualifier.

Programs written in "scripting" languages like Ruby, Perl, or Python, usually run on both OS X and Linux with no or minor modifications.

Compiled command line programs depending only on the C or C++ standard libraries can usually be ported with little difficulty. However, since Apple has dropped support for GCC in favor of Clang, even this can't be absolutely depended on. GCC and Clang may behave differently in the case of undefined behavior in the C or C++ spec.

Programs that use explicit system calls or a GUI, may be quite difficult to port and may have to be re-written entirely.

  • I was talking about native programs – Tommaso Thea Cioni Mar 1 '17 at 13:20
  • @TommasoTheaCioni: Native programs would fall into the Compiled categories described in the last two paragraphs. – Bart van Ingen Schenau Mar 1 '17 at 14:22
  • @BartvanIngenSchenau I know. – Tommaso Thea Cioni Mar 1 '17 at 16:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.