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.
It’s possible, but I don’t know if it’s worth the trouble.
– Maniero
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.
– Lacobus
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.
– Fernando Silveira