Is it possible to compile C/C++ from Windows/Linux for Macos?

Asked

Viewed 286 times

-1

In a hypothetical environment where I don’t have the system or how to emulate, would it be possible to compile an application in c++? (properly compatible)

I’ve already found some cross-compilers interesting, but they can only generate applications between the various distributions of linux, android and windows.

  • 1

    It’s possible, but I don’t know if it’s worth the trouble.

  • First, it would be necessary to build a compiler capable of generating the machine code (from the C++ source code) compatible with the architecture of this "hypothetical environment" that you mentioned.

  • Researching a little on the subject I found some tools that apparently require a good job to be prepared but at the end the expected goal is achieved. The following links are: http://www.sandroid.org/imcross/ http://devs.openttd.org/~truebrain/Compile-farm/apple-darwin9.txt https://github.com/tpoechtrager/osxcross I hope I helped you.

1 answer

-1

Yes, it is possible. In fact, C++ compilers alone always generate cross-platform code. What makes the code incompatible is when the programmer uses some library or command that is not available on another platform.

For example, if your code uses the Winapi it will obviously not run out of Windows, this is not the fault of the compiler, it is because Winapi only exists in Windows.

Another thing, if you write one system("cls"); your code will not run out of Windows because cls is a batch command to clean the cmd.exe window, and this obviously only exists in Windows. (The equivalent in Linux would be clear)

In short: Who makes the C++ code depend on the platform is not the compiler, but the programmer.

  • 3

    Negative, C/C++ compilers do not generate cross-platform code. However simple the program is to compile under Linux, it generates a ELF, compile in Windows generates a PE and compile into macOS generates a Mach-O

Browser other questions tagged

You are not signed in. Login or sign up in order to post.