Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compile Windows binaries on a Linux machine?

At my work, all of the project data resides on an NFS that is accessible from both Linux and Windows machines (using Samba). All of the work is done on Linux, but I'm toying with the idea of compiling some of tools for Windows so that I can debug with Visual Studio.

I already have a nice makefile that can build the code for both 32-bit or 64-bit Linux using different targets. Assuming I have Windows versions of all the external libraries somewhere on the NFS, and assuming the code is clean enough to compile under Windows, is it possible to compile and link my program for Windows using the existing makefile, on Linux? Ideally I'd like to call the makefile once and have it build all three of 32-bit Linux, 64-bit Linux and Windows.

An added plus would be the option to compile it with any Visual Studio metadata to make it easy to debug.

like image 864
Nathan Fellman Avatar asked Oct 04 '09 15:10

Nathan Fellman


People also ask

Can you compile Windows programs on Linux?

mingw32 exists as a package for Linux. You can cross-compile and -link Windows applications with it. There's a tutorial here at the Code::Blocks forum. Mind that the command changes to x86_64-w64-mingw32-gcc-win32 , for example.

Can you compile EXE on Linux?

"I compiled a c file on my Linux machine and named it test.exe, is it possible to run that file on windows?" - It is absolutely possible to compile a Windows executable on Linux.

Can you run a Linux binary on Windows?

The Windows Subsystem for Linux (WSL) is Microsoft's technology stack that enables native Linux binaries to run in a Windows user environment without the need to install a full fledged Linux distro — native or virtual.


1 Answers

Yes, you can achieve that with MinGW for example.

However, you will probably have to adapt one or two options in your makefile.

like image 144
Sobe Avatar answered Sep 18 '22 10:09

Sobe