Install MSYS2, open its UCRT64 terminal, and install the GCC package with pacman -S mingw-w64-ucrt-x86_64-gcc. It includes g++. Follow the official installation guide, then verify the installation with g++ --version. The screenshots below illustrate an older Windows installation. Use the paths and versions for your machine.
A simple example
Run a first program
Start withA source file
Do thisRun the program
ResultReady
Print a single word to check that your tools can run a program.lesson.cpp
A coding club shares its Windows laptops between classes. Open a fresh terminal and run g++ --version. A version line tells the next student that the shell can find the C++ tool.
GNU Compiler Collection (GCC) setup on Windows using MinGW
Open a new terminal and run g++ --version. If the command is unavailable, install the tool or check your PATH.
Install the MinGW in the following default directory C:\MinGW and you can move the MinGW software to another location as per your wish.
Check the MinGW is updated the Environment Variable or not, by opening the command prompt and execute the command g++ --version. It will show the installed GCC's version otherwise follow the below steps to setup the environment variable path.
Step by Step installation guide of MinGW
1. Open the legacy MinGW installer and select Install.
2. Select Continue.
3. Wait for the installer to download its packages, then select Continue.
4. Mark the GCC package for installation. For C++ select the G++ package.
5. Choose Installation, then Apply Changes.
6. Select Apply to install the selected packages.
7. Close the installer.
Advertisements
Set Path of MinGW in Windows system environment variables
1. Locate the directory containing g++.exe. Copy its path.
2. Press Windows + R and enter rundll32.exe sysdm.cpl,EditEnvironmentVariables to open Environment Variables.
Alternatively, search Windows for “environment variables”.
3. Under User variables, select Path and choose Edit.
4. Select New, paste the directory you copied, and confirm with OK.
5. Open a new terminal and run g++ --version to verify that Windows can find the tool.