Install a C++ Compiler on Windows (3 Ways)
To write C++ you need two things: an editor to type the code and a compiler to turn it into an executable (the introduction explains why C++ must be compiled). Windows doesn't come with a C++ compiler, so this lesson shows three proven ways to set one up, how to check it works, and how to compile and run your first program.
Which option should you choose?
| Option | Compiler | Best for | Download size |
|---|---|---|---|
| 1. Visual Studio Community | MSVC (cl.exe) | Beginners on Windows who want one-click build, run and debugging | Large (several GB) |
| 2. MSYS2 + MinGW-w64 | GCC (g++) | Learning the command line; the same compiler used on Linux and in most tutorials | Small (a few hundred MB) |
| 3. VS Code + g++ | GCC from option 2 | A light editor with IntelliSense, if you already use VS Code | Small |
Recommendation: install Visual Studio Community if you want the easiest start. Install MSYS2 g++ (optionally with VS Code) if you want to understand what happens behind the "Run" button. Many developers have both.
Option 1: Visual Studio Community (MSVC)
Visual Studio Community is Microsoft's free full IDE for students, individuals and small teams. Note that Visual Studio and VS Code are different products.
- Download Visual Studio Community from
visualstudio.microsoft.comand run the installer. - On the Workloads tab, tick "Desktop development with C++". This is the important step: without this workload Visual Studio has no C++ compiler. Keep the default optional components (MSVC build tools and the Windows SDK).
- Click Install and wait for the download to finish.
- Start Visual Studio, choose Create a new project, select Console App (with the C++ tag) and click Next, then Create.
- Visual Studio creates a file with a "Hello World!" program. Press Ctrl+F5 (Start Without Debugging). A console window shows the output.
To use a newer language standard, open Project > Properties > C/C++ > Language > C++ Language Standard and pick ISO C++20.
You can also compile from the command line. Open "Developer Command Prompt for VS" from the Start menu (a normal Command Prompt doesn't know where cl.exe is), go to your folder, and run:
cl /EHsc /std:c++20 hello.cpp
hello.exe
/EHsc turns on standard C++ exception handling, and /std:c++20 selects the standard. The result is hello.exe.
Already have Visual Studio for C# or ASP.NET Core? It may not include C++. Open the Visual Studio Installer, click Modify, and add the "Desktop development with C++" workload.
Option 2: MSYS2 + MinGW-w64 (g++)
GCC (the GNU Compiler Collection) is the standard compiler on Linux. MinGW-w64 is GCC built for Windows, and MSYS2 is the easiest way to install and update it.
- Download the installer from
msys2.organd install it to the default folder,C:\msys64. - When it finishes, an MSYS2 UCRT64 terminal opens. Install the compiler with:
Press Enter and then Y to confirm.pacman -S mingw-w64-ucrt-x86_64-gcc - Add the compiler folder to the Windows PATH, so you can use
g++from any terminal: search Windows for "Edit the system environment variables" > Environment Variables > select Path under your user > Edit > New > addC:\msys64\ucrt64\bin. - Open a new PowerShell or Command Prompt window (old windows don't see the PATH change) and check the version:
g++ --version
The first line shows the GCC version; on Windows it mentions the MSYS2 build. Here is the same command on the g++ 14.2 we used to test every program in this course:
If you see a version number, the compiler is installed. Keep it updated later with pacman -Syu in the MSYS2 terminal.
Option 3: VS Code with g++
- Install g++ with option 2 first. VS Code is only an editor; it doesn't include a compiler.
- Install VS Code from
code.visualstudio.com. - Open the Extensions view (Ctrl+Shift+X) and install "C/C++" by Microsoft (IntelliSense and debugging). The "C/C++ Extension Pack" adds CMake support too.
- Open a folder (File > Open Folder), create
hello.cpp, and click the Run C/C++ File button (the play icon at the top right). The first time, choose "C/C++: g++.exe build and debug active file".
VS Code creates a .vscode/tasks.json file with the compile command. You can add "-std=c++20", "-Wall" and "-Wextra" to its args list.
No installation: online compilers
To try a few lines on any computer, you can use an online compiler such as Compiler Explorer (godbolt.org) or OnlineGDB. They're great for quick experiments, but install a real compiler for this course: you'll need it for projects, files and debugging.
Compile and run your first program
Create a folder such as C:\cpp-practice, and in it a file named hello.cpp:
#include <iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
std::cout << "Welcome to C++ at MakeMyCodes" << std::endl;
return 0;
}
Open a terminal in that folder and compile it with g++:
g++ -std=c++20 -Wall -Wextra hello.cpp -o hello
| Part | Meaning |
|---|---|
g++ | The C++ compiler (use g++, not gcc, for C++ files) |
-std=c++20 | Use the C++20 standard |
-Wall -Wextra | Turn on useful warnings. Always use them while learning: they catch real bugs |
hello.cpp | The source file to compile |
-o hello | Name of the output program (hello.exe on Windows). Without -o, g++ names it a.exe (a.out on Linux) |
If the compile succeeds, g++ prints nothing. Silence means success. Now run the program: .\hello.exe in PowerShell, hello in Command Prompt, ./hello on Linux or macOS:
Every time you change the source code, you must compile again before running. Running the old executable runs the old code. This is the most common surprise for people coming from Python.
Common setup errors and fixes
| Error | Cause and fix |
|---|---|
'g++' is not recognized as an internal or external command | The compiler folder isn't on PATH, or the terminal was opened before you changed PATH. Add C:\msys64\ucrt64\bin and open a new terminal. |
fatal error: nothere.cpp: No such file or directory | The terminal isn't in the folder that contains the file, or the name is misspelt. Use cd to go to the folder, and dir to check the name. |
'cl' is not recognized... | Use the "Developer Command Prompt for VS", which sets up the MSVC paths. |
| Visual Studio has no C++ project templates | The "Desktop development with C++" workload isn't installed. Add it in the Visual Studio Installer. |
| Changes don't appear when I run the program | You ran the old executable. Compile again first. |
| Windows warns about the new .exe, or antivirus blocks it | New unsigned executables sometimes trigger this. Allow your practice folder in the antivirus if needed. |
Here is the real message g++ prints when the source file can't be found:
Interview questions
What is the difference between a compiler and an IDE?
A compiler (g++, MSVC cl.exe, Clang) translates source code into an executable. An IDE (Visual Studio, CLion, or VS Code with extensions) is an editor plus tools (build buttons, IntelliSense, debugger) that call the compiler for you.
Name some popular C++ compilers.
GCC (g++) on Linux and through MinGW-w64 on Windows; Microsoft Visual C++ (MSVC) in Visual Studio; and Clang/LLVM, the default on macOS (Xcode), also available on Windows and Linux.
What is the difference between gcc and g++?
Both belong to GCC. g++ treats files as C++ and automatically links the C++ standard library. gcc is meant for C; compiling C++ with it often fails at the link step because the C++ library isn't linked.
Summary
- You need an editor and a compiler; Windows has neither built in for C++.
- Visual Studio Community with "Desktop development with C++" is the easiest all-in-one setup.
- MSYS2 gives you g++ (MinGW-w64); add
C:\msys64\ucrt64\binto PATH and check withg++ --version. - Compile with
g++ -std=c++20 -Wall -Wextra file.cpp -o program, then run the program. Recompile after every change.
Next lesson: C++ syntax and program structure: what every line of the hello-world program means.