Installing VS Code and the GCC Compiler

Topic 5 of 13

Welcome to your C++ journey! To start implementing C++ code practically, we need to set up the necessary tools. This guide provides a complete, step-by-step walkthrough of installing the editor, the necessary add-ons, and the crucial translator (the compiler).

This setup process can be broken down into three main parts:

  1. Installing Visual Studio (VS) Code (the basic text editor).
  2. Installing the C++ Extension inside VS Code.
  3. Installing and configuring the C++ Compiler (MinGW/MSYS2).

 

Phase 1: Understanding Your Tools (Simple Definitions)

Before we start downloading, let's quickly define the essential tools:

Tool

Simple Definition

Detail

VS Code The basic text editor where you write your C++ code. VS Code provides the fundamental tools for writing and organizing your code files.
C++ Extension An add-on that helps VS Code understand C++ syntax. This allows VS Code to provide helpful features like syntax highlighting and error checking specifically for C++.
Compiler The "translator" that converts C++ code into computer instructions. C++ is high-level language; the compiler (like MSYS2) is essential for turning your written program into an application your system can actually run.

 

Phase 2: Installing VS Code and the C++ Extension

Step 1: Download VS Code

  • Open your browser (Google or another browser).
  • Search for "VS code for C++".
  • Click the first result (or click here), go to the site, and click the Download link.
  • Select the correct download for your operating system (Windows or Mac). The download will begin.
  • Step 2: Install VS Code

  • Open the downloaded installer file.
  • Review and select I accept the agreement.
  • Click Next repeatedly.
  • You will see three checkboxes; you may mark these, or skip them if you prefer (either way is fine).
  • Click Next, then Install.
  • Step 3: Install the C++ Extension

  • Open VS Code after installation.
  • Click the Extensions icon (usually on the sidebar).
  • Search for C++ extension.
  • Click on the C/C++ Extension and select Install.

Try It Yourself Prompt: Take a moment to look at the VS Code interface. If you've never used a code editor before, how does it differ from a standard text document like Microsoft Word or Notes?

 

Phase 3: Installing and Configuring the C++ Compiler (MSYS2)

The compiler is crucial because, without it, your computer cannot understand the instructions you write. We are using MSYS2 as our compiler toolset.

Step 4: Download the Compiler

  1. Go back to the browser where you downloaded VS Code.
  2. Scroll down the page until you see MSYS2 and click the link (or click here).
  3. Find the installation section and click the provided link to download the compiler installer.

Step 5: Install the Compiler

  1. Open the downloaded compiler installer file.
  2. Click Next.
  3. Confirm the installation path and click Next.
  4. The components will begin unpacking, and installation will start.
  5. When the process finishes, a command box will appear.
  6. Minimize this box for now.

Step 6: Finalizing the Compiler Setup

You need to run a specific command to complete the setup.

  1. In the installation interface (the box that appeared), paste this specific setup code ( $ pacman -S mingw-w64-ucrt-x86_64-gcc).
  2. Press Enter. This starts the final installation process.
  3. Once this process finishes, the compiler is fully installed on your system.

Step 7: Verification Check

To confirm the compiler is ready, run this command:

  1. Type gcc --version.
  2. Press Enter.
  3. If successful, you will see the compiler version number (e.g., 15.1.0) appear.

Try It Yourself Challenge: If you see the version number (like 15.1.0), congratulations—your compiler is running successfully! If you see an error, it means the system doesn't know where the compiler is, which we fix in the next step.

 

Phase 4: Setting the Environment Path

Even if the compiler is installed, the operating system might not know where to find it. Setting the "Path" tells your system exactly where the executable files are located.

Step 8: Copy the Compiler Path

  1. Go to the file location where the compiler was installed (often in your C drive).
  2. Navigate through the folders: MSYS 64 > UCRT 64 > bin.
  3. Click once in the address bar at the top (the space showing the path).
  4. Copy this entire path.

Step 9: Edit System Environment Variables

  1. Go to your system search bar and search for Edit environment.
  2. Click on the option Edit environment variables for your account.
  3. In the new window, find and click on Path.
  4. Click New.
  5. Paste the path you copied in Step 8.
  6. Click OK.
  7. Click OK again to close the window.

Your environment setup is now complete.

 

Phase 5: Running Your First Program

Now, let's test if the entire environment—VS Code, the Extension, and the Path—works together.

  1. Open VS Code.
  2. Go to File and select New File.
  3. Save the file immediately, giving it a name and adding the essential C++ extension: .cpp (e.g., hello.cpp).

Write a simple test program (we will learn the specifics later). For example:

 

# include <iostream>
using namespace std;
int main(){
      cout<<"Hello World! I am learning C++ with 7 Scribes!";
      return 0;
}

 

  1. Save the file again (File > Save), or just press Ctrl+S.
  2. Go to Terminal and select New Terminal ( Ctrl+Shift+ ` is the sort cut key).
  3. In the terminal, you will see the path of the folder where your new file is located.
  4. Run the necessary commands to execute the program, gcc "FileName" -o "ExecuteAbleFileName.exe" and press enter. (you will learn these commands soon).
  5. For example: gcc hello.cpp -o hello.exe
  6. If successful, the output "Hello World" will appear, confirming your setup is fully operational.

Reflection Prompt: If you successfully saw "Hello World", you have successfully created your entire C++ development environment! This is a majorfirst step in learning C++ step by step.

 

Troubleshooting and Next Steps

If you encounter any errors (e.g., if VS Code is not running properly after installation), please seek assistance.

Engagement Boost: What aspect of the C++ setup—the compiler, the extension, or VS Code—do you find most confusing? Share your thoughts below!