The Windows and Linux executables use two different incompatible formats:
On Windows, this is the Portable Executable format .
On Linux, this is ELF (Executable and Bound Format) .
Each format uses the features of the OS on which they should work, so they usually can not be run on another platform.
In addition, the executable file contains only a small part of the code that is executed after it is loaded into memory. The executable file is associated with system libraries that provide most of the functions that allow the program to interact with the system.
Since the systems are very different from each other, the libraries are different, and the program, say, Linux, cannot be run on FreeBSD, despite the fact that the latter also uses ELF because they are not connected to the same libraries.
To compile the Windows executable on Linux, you can use a method known as cross-compilation. A compiler is, after all, just a program that writes to a binary file, so any compiler can theoretically write code for any platform if the target system libraries are available.
The MinGW-w64 project provides a toolchain that enables this. For example, you can install it on debian-based systems using the sudo apt-get install mingw-w64 .
Installed executables can be used as follows:
i686-w64-mingw32-gcc hello.c -o hello32.exe # 32-bit x86_64-w64-mingw32-gcc hello.c -o hello64.exe # 64-bit
SirDarius
source share