Yes, it is possible. In fact, C ++ compilers by themselves 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 WinAPI it obviously will not run out of Windows, this is not the compiler's fault, it's because WinAPI only exists in Windows.
Another thing, if you write a system("cls");
your code will not run outside of Windows, because cls
is a batch command to clear the cmd.exe window, and this obviously only exists in Windows. (The equivalent on Linux would be clear
)
In short: Who makes C ++ code depend on platform is not the compiler, but the programmer.