Can this C program , that uses purely an unlinked C stdlib and is compiled for Linux, run on Windows?
The question is a bit specific, so assume the following:
- The program's C source code does not explicitly use platform-specific functions (it does not explicitly use system calls, for example).
- To interact with the OS, the source code uses the C stdlib.
- The stdlib is not linked at compile time.
- The program was compiled for Linux on a machine running Linux, then moved to another machine running Windows.
- Before executing the program on Windows, the Linux executable is (somehow) converted to a format compatible with Windows.
- Both machines have the same hardware.
- Both machines have a implementation of the C stdlib.
Now for the question(s):
- Given all the assumptions above, can the program execute on Windows? If not, why?
- If there's an assumption that is incorrect, why is that?
The binaries on Windows and Linux have very different format, so one cannot run on the other. Linux shared libraries are not at all the same as Windows DLL.
Cross-system execution is achieved by either of:
- Re-compilation for the target system (many compilers are capable of compiling on system A for execution on B)
- Running on an emulator, such as WINE, CrossOver and others
- Running in a virtual machine, Windows Subsystem for Linux (WSL), Docker or similar.
No. The executable format of Linux is not compatible with Windows. You would have to recompile the program for Windows.
Alternatively, you could run the program natively in the Windows Subsystem for Linux or in a Virtual Machine running Linux.