The last time I had to compile code in a purely "Microsoft Windows" operating system was in 2019, so I am adding some updated information just in case I continue to exist and have an inkling to compile code for developing or deepening mathematical insight or understanding.
1.
https://www.msys2.org/ for the compiler
2. Install some tools like the mingw-w64 GCC to start compiling projects. Run the following command in the MSYS2 terminal:
pacman -S mingw-w64-ucrt-x86_64-gcc
3. I also ran the following command:
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
It skips what is already up to date, then I choose all (gdb, git, etc)
[note to self: appears to get stuck at step 16/35 (ncurses), but then continues. Same with 20/35 (openssl)]
see:
https://code.visualstudio.com/docs/cpp/config-mingw#_prerequisitesoutput in msys2 ucrt (Universa; C Runtime) environment:
missi@coyote2 UCRT64 ~
$ pacman -S mingw-w64-ucrt-x86_64-gcc
resolving dependencies...
looking for conflicting packages...
Packages (17) mingw-w64-ucrt-x86_64-binutils-2.45-2
mingw-w64-ucrt-x86_64-crt-git-13.0.0.r124.g2717de84e-1
mingw-w64-ucrt-x86_64-gcc-libs-15.2.0-8
mingw-w64-ucrt-x86_64-gettext-runtime-0.26-1
mingw-w64-ucrt-x86_64-gmp-6.3.0-2
mingw-w64-ucrt-x86_64-headers-git-13.0.0.r124.g2717de84e-1
mingw-w64-ucrt-x86_64-isl-0.27-1
mingw-w64-ucrt-x86_64-libiconv-1.18-1
mingw-w64-ucrt-x86_64-libwinpthread-13.0.0.r124.g2717de84e-1
mingw-w64-ucrt-x86_64-mpc-1.3.1-2
mingw-w64-ucrt-x86_64-mpfr-4.2.2-1
mingw-w64-ucrt-x86_64-tzdata-2025b-2
mingw-w64-ucrt-x86_64-windows-default-manifest-6.4-4
mingw-w64-ucrt-x86_64-winpthreads-13.0.0.r124.g2717de84e-1
mingw-w64-ucrt-x86_64-zlib-1.3.1-1
mingw-w64-ucrt-x86_64-zstd-1.5.7-1
mingw-w64-ucrt-x86_64-gcc-15.2.0-8
Total Download Size: 69.63 MiB
Total Installed Size: 545.50 MiB
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
mingw-w64-ucrt-x... 1453.5 KiB 861 KiB/s 00:02 [###########] 100%
mingw-w64-ucrt-x... 4.6 MiB 507 KiB/s 00:09 [###########] 100%
mingw-w64-ucrt-x... 6.2 MiB 675 KiB/s 00:09 [###########] 100%
mingw-w64-ucrt-x... 725.4 KiB 693 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 1050.1 KiB 118 KiB/s 00:09 [###########] 100%
mingw-w64-ucrt-x... 6.4 MiB 609 KiB/s 00:11 [###########] 100%
mingw-w64-ucrt-x... 578.5 KiB 756 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 642.3 KiB 364 KiB/s 00:02 [###########] 100%
mingw-w64-ucrt-x... 541.9 KiB 578 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 403.7 KiB 340 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 128.3 KiB 175 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 221.1 KiB 181 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 92.1 KiB 93.5 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 42.4 KiB 84.7 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 29.5 KiB 70.0 KiB/s 00:00 [###########] 100%
mingw-w64-ucrt-x... 3.0 KiB 12.8 KiB/s 00:00 [###########] 100%
mingw-w64-ucrt-x... 46.6 MiB 1569 KiB/s 00:30 [###########] 100%
Total (17/17) 69.6 MiB 2.27 MiB/s 00:31 [###########] 100%
(17/17) checking keys in keyring [###########] 100%
(17/17) checking package integrity [###########] 100%
(17/17) loading package files [###########] 100%
(17/17) checking for file conflicts [###########] 100%
(17/17) checking available disk space [###########] 100%
:: Processing package changes...
( 1/17) installing mingw-w64-ucrt-x86_64-libwi... [###########] 100%
( 2/17) installing mingw-w64-ucrt-x86_64-tzdata [###########] 100%
( 3/17) installing mingw-w64-ucrt-x86_64-gcc-libs [###########] 100%
( 4/17) installing mingw-w64-ucrt-x86_64-libiconv [###########] 100%
( 5/17) installing mingw-w64-ucrt-x86_64-gette... [###########] 100%
( 6/17) installing mingw-w64-ucrt-x86_64-zlib [###########] 100%
( 7/17) installing mingw-w64-ucrt-x86_64-zstd [###########] 100%
( 8/17) installing mingw-w64-ucrt-x86_64-binutils [###########] 100%
( 9/17) installing mingw-w64-ucrt-x86_64-heade... [###########] 100%
(10/17) installing mingw-w64-ucrt-x86_64-crt-git [###########] 100%
(11/17) installing mingw-w64-ucrt-x86_64-gmp [###########] 100%
(12/17) installing mingw-w64-ucrt-x86_64-isl [###########] 100%
(13/17) installing mingw-w64-ucrt-x86_64-mpfr [###########] 100%
(14/17) installing mingw-w64-ucrt-x86_64-mpc [###########] 100%
(15/17) installing mingw-w64-ucrt-x86_64-windo... [###########] 100%
(16/17) installing mingw-w64-ucrt-x86_64-winpt... [###########] 100%
(17/17) installing mingw-w64-ucrt-x86_64-gcc [###########] 100%
missi@coyote2 UCRT64 ~
$ gcc --version
gcc.exe (Rev8, Built by MSYS2 project) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
missi@coyote2 UCRT64 ~
$ pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
warning: mingw-w64-ucrt-x86_64-binutils-2.45-2 is up to date -- skipping
warning: mingw-w64-ucrt-x86_64-crt-git-13.0.0.r124.g2717de84e-1 is up to date -- skipping
warning: mingw-w64-ucrt-x86_64-gcc-15.2.0-8 is up to date -- skipping
warning: mingw-w64-ucrt-x86_64-headers-git-13.0.0.r124.g2717de84e-1 is up to date -- skipping
warning: mingw-w64-ucrt-x86_64-libwinpthread-13.0.0.r124.g2717de84e-1 is up to date -- skipping
warning: mingw-w64-ucrt-x86_64-winpthreads-13.0.0.r124.g2717de84e-1 is up to date -- skipping
:: There are 7 members in group mingw-w64-ucrt-x86_64-toolchain:
:: Repository ucrt64
1) mingw-w64-ucrt-x86_64-gdb
2) mingw-w64-ucrt-x86_64-gdb-multiarch
3) mingw-w64-ucrt-x86_64-libmangle-git
4) mingw-w64-ucrt-x86_64-make 5) mingw-w64-ucrt-x86_64-pkgconf
6) mingw-w64-ucrt-x86_64-tools-git
7) mingw-w64-ucrt-x86_64-winstorecompat-git
Enter a selection (default=all):
resolving dependencies...
looking for conflicting packages...
Packages (35) binutils-2.45-1 bison-3.8.2-5 diffstat-1.68-1
diffutils-3.12-1 dos2unix-7.5.2-1 flex-2.6.4-4
m4-1.4.19-2 make-4.4.1-2
mingw-w64-ucrt-x86_64-bzip2-1.0.8-3
mingw-w64-ucrt-x86_64-expat-2.7.1-2
mingw-w64-ucrt-x86_64-libffi-3.5.1-1
mingw-w64-ucrt-x86_64-libsystre-1.0.2-1
mingw-w64-ucrt-x86_64-libtre-0.9.0-1
mingw-w64-ucrt-x86_64-mpdecimal-4.0.1-1
mingw-w64-ucrt-x86_64-ncurses-6.5.20241228-3
mingw-w64-ucrt-x86_64-openssl-3.5.2-1
mingw-w64-ucrt-x86_64-python-3.12.11-1
mingw-w64-ucrt-x86_64-readline-8.3.001-1
mingw-w64-ucrt-x86_64-sqlite3-3.50.4-1
mingw-w64-ucrt-x86_64-tcl-8.6.16-1
mingw-w64-ucrt-x86_64-termcap-1.3.1-7
mingw-w64-ucrt-x86_64-tk-8.6.16-1
mingw-w64-ucrt-x86_64-xxhash-0.8.3-1
mingw-w64-ucrt-x86_64-xz-5.8.1-2 patch-2.7.6-3
texinfo-7.2-2 texinfo-tex-7.2-2 base-devel-2024.11-1
mingw-w64-ucrt-x86_64-gdb-16.3-1
mingw-w64-ucrt-x86_64-gdb-multiarch-16.3-1
mingw-w64-ucrt-x86_64-libmangle-git-13.0.0.r124.g2717de84e-1
mingw-w64-ucrt-x86_64-make-4.4.1-3
mingw-w64-ucrt-x86_64-pkgconf-1~2.5.1-1
mingw-w64-ucrt-x86_64-tools-git-13.0.0.r124.g2717de84e-1
mingw-w64-ucrt-x86_64-winstorecompat-git-13.0.0.r124.g2717de84e-1
Total Download Size: 63.21 MiB
Total Installed Size: 415.02 MiB
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
mingw-w64-ucrt-x... 4.6 MiB 612 KiB/s 00:08 [###########] 100%
binutils-2.45-1-... 5.7 MiB 444 KiB/s 00:13 [###########] 100%
mingw-w64-ucrt-x... 2.7 MiB 450 KiB/s 00:06 [###########] 100%
mingw-w64-ucrt-x... 6.3 MiB 415 KiB/s 00:16 [###########] 100%
mingw-w64-ucrt-x... 7.9 MiB 497 KiB/s 00:16 [###########] 100%
mingw-w64-ucrt-x... 2.3 MiB 679 KiB/s 00:03 [###########] 100%
texinfo-7.2-2-x86_64 1473.6 KiB 281 KiB/s 00:05 [###########] 100%
mingw-w64-ucrt-x... 1747.6 KiB 308 KiB/s 00:06 [###########] 100%
mingw-w64-ucrt-x... 23.2 MiB 1004 KiB/s 00:24 [###########] 100%
mingw-w64-ucrt-x... 866.4 KiB 127 KiB/s 00:07 [###########] 100%
mingw-w64-ucrt-x... 2.0 MiB 258 KiB/s 00:08 [###########] 100%
bison-3.8.2-5-x86_64 777.2 KiB 339 KiB/s 00:02 [###########] 100%
make-4.4.1-2-x86_64 507.6 KiB 179 KiB/s 00:03 [###########] 100%
mingw-w64-ucrt-x... 500.2 KiB 382 KiB/s 00:01 [###########] 100%
diffutils-3.12-1... 385.3 KiB 325 KiB/s 00:01 [###########] 100%
dos2unix-7.5.2-1... 446.5 KiB 222 KiB/s 00:02 [###########] 100%
mingw-w64-ucrt-x... 337.5 KiB 203 KiB/s 00:02 [###########] 100%
flex-2.6.4-4-x86_64 303.5 KiB 267 KiB/s 00:01 [###########] 100%
m4-1.4.19-2-x86_64 238.1 KiB 231 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 164.9 KiB 153 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 154.9 KiB 193 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 138.8 KiB 443 KiB/s 00:00 [###########] 100%
mingw-w64-ucrt-x... 118.7 KiB 304 KiB/s 00:00 [###########] 100%
patch-2.7.6-3-x86_64 96.1 KiB 384 KiB/s 00:00 [###########] 100%
mingw-w64-ucrt-x... 99.6 KiB 121 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 79.0 KiB 109 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 76.5 KiB 173 KiB/s 00:00 [###########] 100%
mingw-w64-ucrt-x... 43.1 KiB 77.7 KiB/s 00:01 [###########] 100%
diffstat-1.68-1-... 28.9 KiB 70.7 KiB/s 00:00 [###########] 100%
mingw-w64-ucrt-x... 27.3 KiB 96.0 KiB/s 00:00 [###########] 100%
mingw-w64-ucrt-x... 25.1 KiB 73.9 KiB/s 00:00 [###########] 100%y
texinfo-tex-7.2-... 24.2 KiB 33.2 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 22.9 KiB 40.6 KiB/s 00:01 [###########] 100%
mingw-w64-ucrt-x... 9.7 KiB 13.9 KiB/s 00:01 [###########] 100%
base-devel-2024.... 1875.0 B 4.81 KiB/s 00:00 [###########] 100%
Total (35/35) 63.2 MiB 2.09 MiB/s 00:30 [###########] 100%
(35/35) checking keys in keyring [###########] 100%
(35/35) checking package integrity [###########] 100%
(35/35) loading package files [###########] 100%
(35/35) checking for file conflicts [###########] 100%
(35/35) checking available disk space [###########] 100%
:: Processing package changes...
( 1/35) installing binutils [###########] 100%
( 2/35) installing m4 [###########] 100%
( 3/35) installing bison [###########] 100%
( 4/35) installing diffstat [###########] 100%
( 5/35) installing diffutils [###########] 100%
( 6/35) installing dos2unix [###########] 100%
( 7/35) installing flex [###########] 100%
( 8/35) installing texinfo [###########] 100%
( 9/35) installing texinfo-tex [###########] 100%
(10/35) installing make [###########] 100%
(11/35) installing patch [###########] 100%
Optional dependencies for patch
ed: for patch -e functionality
(12/35) installing base-devel [###########] 100%
(13/35) installing mingw-w64-ucrt-x86_64-expat [###########] 100%
(14/35) installing mingw-w64-ucrt-x86_64-libtre [###########] 100%
(15/35) installing mingw-w64-ucrt-x86_64-libsystre [###########] 100%
(16/35) installing mingw-w64-ucrt-x86_64-ncurses [###########] 100%
(17/35) installing mingw-w64-ucrt-x86_64-bzip2 [###########] 100%
(18/35) installing mingw-w64-ucrt-x86_64-libffi [###########] 100%
(19/35) installing mingw-w64-ucrt-x86_64-mpdecimal [###########] 100%
(20/35) installing mingw-w64-ucrt-x86_64-openssl [###########] 100%
Optional dependencies for mingw-w64-ucrt-x86_64-openssl
mingw-w64-ucrt-x86_64-ca-certificates
(21/35) installing mingw-w64-ucrt-x86_64-termcap [###########] 100%
(22/35) installing mingw-w64-ucrt-x86_64-readline [###########] 100%
(23/35) installing mingw-w64-ucrt-x86_64-sqlite3 [###########] 100%
Optional dependencies for mingw-w64-ucrt-x86_64-sqlite3
mingw-w64-ucrt-x86_64-tcl: for sqlite3_analyzer [pending]
(24/35) installing mingw-w64-ucrt-x86_64-tcl [###########] 100%
(25/35) installing mingw-w64-ucrt-x86_64-tk [###########] 100%
(26/35) installing mingw-w64-ucrt-x86_64-xz [###########] 100%
(27/35) installing mingw-w64-ucrt-x86_64-python [###########] 100%
(28/35) installing mingw-w64-ucrt-x86_64-xxhash [###########] 100%
(29/35) installing mingw-w64-ucrt-x86_64-gdb [###########] 100%
Optional dependencies for mingw-w64-ucrt-x86_64-gdb
mingw-w64-ucrt-x86_64-python-pygments: for syntax highlighting
(30/35) installing mingw-w64-ucrt-x86_64-gdb-m... [###########] 100%
Optional dependencies for mingw-w64-ucrt-x86_64-gdb-multiarch
mingw-w64-ucrt-x86_64-python-pygments: for syntax highlighting
(31/35) installing mingw-w64-ucrt-x86_64-libma... [###########] 100%
(32/35) installing mingw-w64-ucrt-x86_64-make [###########] 100%
(33/35) installing mingw-w64-ucrt-x86_64-pkgconf [###########] 100%
(34/35) installing mingw-w64-ucrt-x86_64-tools-git [###########] 100%
(35/35) installing mingw-w64-ucrt-x86_64-winst... [###########] 100%
:: Running post-transaction hooks...
(1/1) Updating the info directory file...
missi@coyote2 UCRT64 ~
$
Here, "missi" is the directory C:\Users\missi on an old computer I named "coyote2"
4. To update MSYS2, run :
pacman -Suy
the output:
missi@coyote2 UCRT64 ~
$ pacman -Suy
:: Synchronizing package databases...
clangarm64 491.3 KiB 202 KiB/s 00:02 [###########] 100%
mingw32 125.0 KiB 64.7 KiB/s 00:02 [###########] 100%
mingw64 470.1 KiB 190 KiB/s 00:02 [###########] 100%
ucrt64 515.6 KiB 219 KiB/s 00:02 [###########] 100%
clang64 503.5 KiB 199 KiB/s 00:03 [###########] 100%
msys 407.6 KiB 181 KiB/s 00:02 [###########] 100%
:: Starting core system upgrade...
warning: terminate other MSYS2 programs before proceeding
resolving dependencies...
looking for conflicting packages...
Packages (3) mintty-1~3.8.1-1 msys2-runtime-3.6.4-2 pacman-6.1.0-19
Total Download Size: 10.05 MiB
Total Installed Size: 54.79 MiB
Net Upgrade Size: 1.71 MiB
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
mintty-1~3.8.1-1... 1310.6 KiB 599 KiB/s 00:02 [###########] 100%
msys2-runtime-3.... 1941.2 KiB 791 KiB/s 00:02 [###########] 100%
pacman-6.1.0-19-... 6.9 MiB 1415 KiB/s 00:05 [###########] 100%
Total (3/3) 10.1 MiB 2025 KiB/s 00:05 [###########] 100%
(3/3) checking keys in keyring [###########] 100%
(3/3) checking package integrity [###########] 100%
(3/3) loading package files [###########] 100%
(3/3) checking for file conflicts [###########] 100%
(3/3) checking available disk space [###########] 100%
:: Processing package changes...
(1/3) upgrading mintty [###########] 100%
(2/3) upgrading msys2-runtime [###########] 100%
(3/3) upgrading pacman [###########] 100%
:: To complete this update all MSYS2 processes including this terminal will be closed. Confirm to proceed [Y/n]
Add the path of your MinGW-w64 bin folder to the Windows PATH environment variable by using the following steps:
1. In the Windows search bar, type Settings to open your Windows Settings.
2. Search for Edit environment variables for your account.
3. In your User variables, select the Path variable and then select Edit.
4. Select New and add the MinGW-w64 destination folder you recorded during the installation process to the list. If you used the default settings above, then this will be the path: C:\msys64\ucrt64\bin.
5. Select OK, and then select OK again in the Environment Variables window to update the PATH environment variable. You have to reopen any console windows for the updated PATH environment variable to be available.
Check your MinGW installationTo check that your MinGW-w64 tools are correctly installed and available, open a new Command Prompt and type:
gcc --version
g++ --version
gdb --version
You should see output that states which versions of GCC, g++ and GDB you have installed.
Microsoft Windows [Version 10.0.19045.6396]
(c) Microsoft Corporation. All rights reserved.
C:\Users\missi>gcc --version
gcc (Rev8, Built by MSYS2 project) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\missi>g++ --version
g++ (Rev8, Built by MSYS2 project) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\missi>gdb --version
GNU gdb (GDB) 16.3
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
C:\Users\missi>
I want to start with something basic and fundamental.
I open classic cmd.exe (evolved from "MS-DOS prompt command line"):
mkdir projects
cd projects
mkdir GCD
cd GCD
code .
The "code ." command opens VS Code in the current working folder, which becomes your "workspace".
When I compiled gcd.c in VS Code, it created output firectory, where gcd.exe is placed, the binary executable program. I can run it in cmd.exe, but not in PowerShell or "terminal" ---
solution?
The command gcd was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\gcd".
PS C:\Users\missi\bin> .\gcd 45 78
gcd(45,78) = 3
Interesting. In Unix/Linux, one would use ./gcd.
Powershell uses .\ backslash
I will add this C:\Users\missi\bin directory to PATH so that I can call it from anywhere. This is where I place my execuable "binaries" ...
__________________________________________________
gcd.c
__________________________________________________
#include <stdio.h>
#include <stdlib.h>
int gcd(int a, int b);
void main(int argc, char *argv[]) {
int x, y, z;
x = atoi(argv[1]);
y = atoi(argv[2]);
z = gcd(x, y);
printf("gcd(%d,%d) = %d\n", x, y, z);
}
int gcd(int a, int b) {
int t;
while (a)
{
t = a;
a = b%a;
b = t;
}
return b;
}