Compiling code in Ubuntu and running on windows

4

Hello, I was wondering how can I compile a C code in Ubuntu and that
run in Windows. I tried to put the extension ".exe" at the end
of the file, but when I sent the executable to my teacher he said
which did not rotate.

    
asked by anonymous 18.06.2017 / 20:10

1 answer

7
  

You can create executables for windows using mingw-w64 . Entering the following command, we can see the list of available packages:

apt-cache search mingw-
  

Among them:

mingw-w64 - Development environment targeting 32- and 64-bit Windows
  

After you install it:

sudo apt-get install mingw-w64
  

I created my executable (32 bits) from the /usr/bin folder, like this:

sudo i686-w64-mingw32-gcc-win32 helloworld.c -o helloworld.exe
  

For 64-bit:

sudo x86_64-w64-mingw32-gcc helloworld.c -o helloworld64.exe
  

Result:

Sources:
How to install mingw32 on Ubuntu? < how to compile for Windows on Linux with gcc / gcc / gcc / gcc / gcc / gcc / g ++?
Compile 64-bit binary with MinGW (Dev-C ++)

    
19.06.2017 / 01:50