Compiling C files on Ubuntu and using the executable on Windows

The standard compiler toolchain on Ubuntu will produce Linux executables, not Windows executables. It is possible to install a cross-compiler that will produce Windows executables - this Stack Overflow question and answers give some hints on how to install and run one.


This is called cross-compiling. You need a "toolchain" (compiler, linker, etc.) that will generate the appropriate code and format, involving:

  • The target processor architecture. In your case is is probably the same (x86 or amd64), but sometimes you cross-compile for a different processor, for instance when you build an executable for an ARM processor on your PC.

  • The target ABI (those are the call conventions used).

  • The right format

  • The right libraries, including system libraries.

Depending on the project, this may be very easy (just a flag or an environment variable to set somewhere) or very difficult.

You'll find a few pointers here, here or here.