Mikhail Mikhail - 6 months ago 52
C Question

Windows 10 Linux Subsystem Bash. How to Compile Executable Specially for Windows Platform with GCC in Linux [issue resolved]

Recently published a new update to the Windows 10 Anniversary Update includes Linux Subsystem based on Ubuntu. I install gcc and g++ with

sudo apt-get install gcc
sudo apt-get install g++
. Write simple C code for test:

#include <stdio.h>
int main(void){
return 0;

And compile it with
gcc -c main.c
but in the directory in which I make a compilation created object file
(but this executable file has built only for Linux Subsystem). If I run it
(in linux terminal) it displays the
. Alright.

My question. How can I compile Windows
with GCC in Linux Subsystem ?


Linux Subsystem works as a Linux-computer. You can only run Linux executables inside it and default gcc creates Linux executables.

To create Windows executables, you need to install mingw cross-compiler:

sudo apt-get install mingw-w64

Then you can create 32-bit Windows executable with:

i686-w64-mingw32-gcc -o main32.exe main.c

And 64-bit Windows executable with:

x86_64-w64-mingw32-gcc -o main64.exe main.c

Note that these Windows executables will not work inside Linux Subsystem, only outside of it.