Compiling code on Ubuntu and running on windows

Asked

Viewed 162 times

4

Hi, I was wondering how can I compile a C code on Ubuntu and what
execute on 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
that did not spin.

1 answer

7


You can create executables for windows using mingw-W64. By typing 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 installing it:

sudo apt-get install mingw-w64

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

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

For 64 bits:

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

Upshot:

resultado da compilação

Sources:
How to install mingw32 on Ubuntu?
How to Compile for Windows on Linux with gcc/g++?
Compile 64-bit Binary with Mingw (Dev-C++)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.