Msys2 offers the same tools as Linux to build software on Windows.
-
Download and install MSYS2 (page,installer). You can also use package managers like
Chocolatey
orScoop
to install MSYS2: Use this command to install with Chocolatey:choco install msys2
Use this command to install with scoop:
scoop install msys2
-
Lunch a bash shell from
cmd
C:\msys64\msys2_shell.cmd -defterm -here -no-start -ucrt64
-
Install
git
pacman -S git
-
Install
gcc
pacman -S mingw-w64-ucrt-x86_64-gcc
-
Install
ninja
pacman -S mingw-w64-ucrt-x86_64-ninja
-
Install
cmake
pacman -S mingw-w64-ucrt-x86_64-cmake
-
Install Visual Studio Code.
-
Install C/C++ Extension Pack for Visual Studio Code. You can also install from commandline
code --install-extension ms-vscode.cpptools-extension-pack
-
The next step is to clone starting repository
git clone https://github.com/hkinke/gscppmsys2.git hello
-
Change the folder, remove
.git
folder, and start a new repositorycd hello rm -rf .git git init
-
Change the replace
gscppmsys2
inCMakeLists.txt
with the name of your project by examplehello
.cmake_minimum_required(VERSION 3.18) project(hello) add_executable(main main.cpp)
-
From Visual Studio Code, choose the
UCRT64
kit, configure, and build your project. -
Lunch you application (you can use Visual Studio Code integrated terminal
Ctrl+Shift+`
)./build/main
which gives the output
hello from Msys2