Installing MinGW-w64 (GCC) on Windows: Options, Setup, and Verification
MinGW-w64 provides GCC-based C/C++ toolchains for Windows, targeting both 32-bit and 64-bit systems. It links against the native Windows runtime libraries, producing executables that run without third‑party runtime DLLs. Compared with the legacy MinGW project (32-bit only and largely unmaintained), MinGW-w64 remains actively updated and supports modern language standards.
When to use MinGW-w64
- Command-line oriented development and learning the C/C++ build process
- Small to medium projects where a lightweight toolchain is preferred
- Cases where no external runtime dependency is desired
- IDEs that bundle MinGW-w64 under the hood (e.g., Code::Blocks bundles, some VS Code setups)
Keep in mind that larger projects typically use build systems (Make, CMake, Ninja). Pure command-line flows require Makefiles or build scripts to scale beyond single-file builds.
Obtaining MinGW-w64 (official builds)
- GCC binary distributions: https://gcc.gnu.org/install/binaries.html (select Microsoft → MinGW-w64)
- MinGW-w64 project downloads: https://www.mingw-w64.org/downloads/ (follow links to prebuilt toolchains, often hosted on SourceForge)
Typical installer choices (SourceForge builds)
- Version: GCC release packaged by the distributor. Pick the latest unless a specific version is required.
- Architecture:
- x86_64: 64-bit Windows
- i686: 32-bit Windows
- Threads:
- posix: POSIX threading model
- win32: Windows threading model Choose based on library compatibility; posix is common for cross-platform builds, win32 for pure Windows targets.
- Exceptions (64-bit):
- seh (Structured Exception Handling): recommended for 64-bit
- sjlj: legacy alternative
- Exceptions (32-bit):
- dwarf: usually faster unwinding for 32-bit, not for 64-bit
- sjlj: portable but slower unwinding
- Revision (build revision): Packager’s build number; default is fine.
Installation steps (SourceForge-style installer)
- Download the online or offline installer from the MinGW-w64 download page.
- Launch the installer.
- Select GCC Version, Architecture (x86_64 for 64-bit, i686 for 32-bit), Threads (posix or win32), and Exceptions (seh for 64-bit; dwarf for 32-bit unless sjlj is required).
- Choose an installation directory, for example:
- C:\mingw-w64\x86_64-\
- Finish the installation and note the bin folder location, e.g. C:\mingw-w64\x86_64-...\mingw64\bin.
PATH configuration (Windows)
-
Add the toolchain’s bin directory to PATH so gcc and g++ are available in shells.
- System Properties → Environment Variables → Edit PATH → add C:\mingw-w64...\mingw64\bin
- Or from a elevated Command Prompt:
setx PATH "%PATH%;C:\mingw-w64\x86_64-...\mingw64\bin"
Verification
-
Open a new terminal and check versions:
gcc --version g++ --version where gcc
Example output (will vary by build):
gcc (x86_64-posix-seh, Built by MinGW-W64 project) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc.
-
Build and run a small program:
Save as hello.c:
#include <stdio.h>
int main(void) { puts("Hello from MinGW-w64!"); return 0; }
Compile and run:
gcc -O2 -Wall -Wextra -o hello.exe hello.c .\hello.exe
Expected output:
Hello from MinGW-w64!
Common selector guidance
- 64-bit targets: x86_64 + seh; threads either posix (portabel libs) or win32 (pure Windows)
- 32-bit targets: i686 + dwarf; use sjlj only if required by specific libraries
- Choose the newest stable GCC unless compatibility requirements dictate otherwise