How to make .exe from C for 32x bit Windows system sitting on 64x bit Linux?

When a team:

gcc -m32 app.c -o app.exe 

An error occurred:

In file included from app.c: 1: 0:
/usr/include/stdio.h:27:10: fatal error: bits / libc-header-start.h: No such file or directory
#include
^ ~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.

1 answer 1

Solved the problem with the error by installing gcc-multilib command

 sudo apt-get install gcc-multilib 

But to create .exe for Windows sitting on Linux you need:

  1. Install a cross-compiler, for example, mingw64 from the package manager.
  2. Then compile as follows: instead of just invoking the gcc command, i686-w64-mingw32-gcc for 32- bit Windows or x86_64-w64-mingw32-gcc for 64- bit Windows should be called.

For example:
i686-w64-mingw32-gcc app.c -o app.exe - for 32x

x86_64-w64-mingw32-gcc app.c -o app.exe - for 64x

  • In order not to write the prefix each time, the calls to utilities in $ (CROSS_COMPILE) are usually written in the Makefile . - 0andriy