Mark Lucernas
Jun 14, 2021

Mingw-w64: GCC compiler for Windows 64 & 32 bits

Compile with GCC/G++ on Linux for Windows.

Installation

Debian Based

sudo apt install mingw-w64

Usage

For 64-bit system

# compile and link
x86_64-w64-mingw32-g++ -static-libgcc -static-libstdc++ main.cpp -o target.exe
# compile and link separately
x86_64-w64-mingw32-g++ -c main.cpp
x86_64-w64-mingw32-g++ -static-libgcc -static-libstdc++ -g main.o -o target.exe

For 32-bit system

# compile and link
i686-w64-mingw32-g++ -static-libgcc -static-libstdc++ main.cpp -o target.exe
# compile and link separately
i686-w64-mingw32-g++ -c main.cpp
i686-w64-mingw32-g++ -static-libgcc -static-libstdc++ -g main.o -o target.exe

NOTE: -static-libgcc -static-libstdc++ compiler options to link the C and C++ standard libraries statically. Fixes missing library errors.

Ref:


Resources