> For the complete documentation index, see [llms.txt](https://kmanu225.gitbook.io/cs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kmanu225.gitbook.io/cs/software-engineering/unix-linux-on-windows-choosing-the-right-environment/mingw-w64-gnu-tools-on-windows.md).

# MinGW-w64: GNU Tools on Windows

[Git Bash](/cs/software-engineering/unix-linux-on-windows-choosing-the-right-environment/git-bash-a-lightweight-unix-like-shell-on-windows.md) gives you a Unix-like shell, but what if you also want to **compile C or C++ applications with GCC** and produce native Windows executables?

That is where **MinGW-w64** comes in.

MinGW-w64 provides [GNU compiler](https://gcc.gnu.org/) toolchains, headers, and libraries for building applications that run directly on Windows.

The key point is: **MinGW-w64 is not Linux. It is a Windows compiler toolchain.**

## What does MinGW-w64 do?

Suppose you have a simple C program:

```c
#include <stdio.h>

int main(void) {
    printf("Hello from Windows!\n");
    return 0;
}
```

With MinGW-w64 GCC, you can compile it as:

```bash
gcc hello.c -o hello.exe
```

The result is:

```
hello.exe
```

That executable runs directly on Windows.

You are using GCC, but you are **not** producing a Linux binary. This is an important difference from compiling the same program inside a Linux environment, where the output would normally be a Linux executable.

## When is MinGW-w64 useful?

MinGW-w64 is a good fit when you want to:

* build native Windows C or C++ applications;
* use GCC or G++ instead of Visual C++;
* keep a similar GNU toolchain across Linux and Windows;
* compile cross-platform projects for Windows;
* use build systems such as CMake with GCC.

A project might therefore use:

```
Linux
  |
  +-- GCC
  +-- CMake
  +-- Make / Ninja

Windows
  |
  +-- MinGW-w64 GCC
  +-- CMake
  +-- Make / Ninja
```

The source code may be largely shared, while each platform produces its own native binaries.

## MinGW-w64 does not provide a full Unix environment

MinGW-w64 is mainly a toolchain. It provides things such as:

```
gcc
g++
Windows headers
Windows libraries
linker tools
```

It does not, by itself, provide a complete Bash environment, Linux package manager, Linux kernel, or POSIX runtime. This means it should not be confused with tools such as Git Bash, Cygwin, or WSL.

For example:

```bash
gcc main.c -o app.exe
```

is exactly the kind of task MinGW-w64 is designed for.

But:

```bash
apt install something
```

or running an existing Linux ELF binary is not.

## Native Windows binaries

One of the main advantages of MinGW-w64 is that the resulting application uses Windows APIs directly.

For example, a program can call Windows-specific APIs:

```c
#include <windows.h>

int main(void) {
    MessageBoxA(NULL, "Hello", "MinGW-w64", MB_OK);
    return 0;
}
```

and compile it with GCC.

The output is still a native Windows application. This is fundamentally different from using a POSIX compatibility layer such as Cygwin.

## Cross-platform projects

MinGW-w64 is particularly useful for software that already supports multiple operating systems.

For example:

```cpp
#ifdef _WIN32
    // Windows-specific implementation
#else
    // Linux / Unix implementation
#endif
```

The same codebase can be compiled with:

```
GCC on Linux
MinGW-w64 GCC on Windows
```

This makes MinGW-w64 common in open-source and cross-platform C/C++ projects.

CMake can also generate builds for MinGW toolchains, so projects do not necessarily need platform-specific build scripts.

## How do you get it?

MinGW-w64 toolchains are available through several distributions and development environments.

One common approach is to install them through **MSYS2**, which adds package management, Bash, and other Unix-style development tools around the MinGW-w64 compiler.

You can also find standalone MinGW-w64 toolchains.

This distinction is useful:

```
MinGW-w64
    |
    +-- compiler
    +-- headers
    +-- libraries
    +-- native Windows binaries
```

while a tool such as MSYS2 provides the larger environment around it.

We will cover that in the next article.

## MinGW-w64 vs Git Bash

These two tools solve different problems.

| Need                        |                       Git Bash | MinGW-w64 |
| --------------------------- | -----------------------------: | --------: |
| Bash shell                  |                        **Yes** |    **No** |
| Git and SSH                 |                        **Yes** |    **No** |
| Unix utilities              |                        **Yes** |    **No** |
| GCC compiler                | Limited / not the main purpose |   **Yes** |
| Build native Windows `.exe` |                Not its purpose |   **Yes** |
| Run Linux binaries          |                         **No** |    **No** |

Git Bash gives you a Unix-like command-line environment. MinGW-w64 gives you a compiler toolchain. They can be used together, but they are not the same thing.

## Should you use MinGW-w64?

Use MinGW-w64 when your requirement is:

> **"I want to build native Windows applications using GCC and GNU development tools."**

Do not use it if your real goal is to run Linux applications or reproduce a Linux environment. For that, you need a different solution like [MSYS2](/cs/software-engineering/unix-linux-on-windows-choosing-the-right-environment/msys2-a-unix-like-development-environment-for-windows.md).
