Build a C Environment on Windows with MSYS2 (UCRT64)

Build a C Environment on Windows with MSYS2 (UCRT64)

Jasper

If you want a clean C/C++ toolchain on Windows, MSYS2 is still one of the best choices.
This guide sets it up in UCRT64 and builds a minimal CMake project.

1) Install MSYS2

Download and install MSYS2 from the official website.
Then open MSYS2 UCRT64 terminal.

2) Update package database

First run:

1
pacman -Syu

If terminal asks to restart, close it and open MSYS2 UCRT64 again, then run:

1
pacman -Syu

3) Install build tools

1
2
3
4
5
pacman -S --needed \
mingw-w64-ucrt-x86_64-gcc \
mingw-w64-ucrt-x86_64-cmake \
mingw-w64-ucrt-x86_64-make \
mingw-w64-ucrt-x86_64-ninja

Check versions:

1
2
3
4
5
gcc --version
g++ --version
cmake --version
make --version
ninja --version

4) Create a minimal CMake project

Folder:

1
2
3
4
hello-c/
CMakeLists.txt
src/
main.c

src/main.c:

1
2
3
4
5
6
#include <stdio.h>

int main(void) {
printf("Hello from C + CMake on MSYS2 UCRT64!\\n");
return 0;
}

CMakeLists.txt:

1
2
3
4
cmake_minimum_required(VERSION 3.20)
project(hello_c C)

add_executable(hello_c src/main.c)

5) Build with Ninja

1
2
3
cmake -S . -B build -G Ninja
cmake --build build
./build/hello_c.exe

You should see:

1
Hello from C + CMake on MSYS2 UCRT64!

6) Build with Make (optional)

1
2
3
cmake -S . -B build-make -G "MinGW Makefiles"
cmake --build build-make
./build-make/hello_c.exe

That is the full setup.
Once this works, you can build almost any small C/C++ project on Windows without IDE lock-in.

  • Title: Build a C Environment on Windows with MSYS2 (UCRT64)
  • Author: Jasper
  • Created at : 2026-03-06 17:35:40
  • Updated at : 2026-03-06 17:35:40
  • Link: https://jasperzpzhang.github.io/windows-msys2-cmake-hello-c/
  • License: This work is licensed under CC BY-NC-SA 4.0.