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:
- π Compiling, Linking and Building C/C++ Applications
- π How to compile for Windows on Linux with gcc/g++?
- π libstdc++-6.dll not found
- π The program canβt start because libgcc_s_dw2-1.dll is missing