DEV Community

Sujal Agre
Sujal Agre

Posted on

Setup C++ in VS Code (Windows 2024)

This blog post will guide you to install C++ in Windows for VS Code

Step 1: Installing VS Code

  1. Download the latest VS Code Setup.exe from this link.
  2. Click on I Accept the agreement and click on Next Image description
  3. Make sure to check all the boxes as shown below and click Next. Image description
  4. Click on Install and wait till its installed. Image description
  5. Click on finish. Image description

Step 2: Installing Required Extensions in VS Code.

  1. Go to the Extensions Tab (Ctrl+Shift+X) in VS Code.
  2. Search up and Install the following Extensions.

Image description
C/C++
Image description
Code Runner
Image description

Step 3: Installing C++ Compiler.

Installing the MinGW-w64 toolchain
Get the latest version of MinGW-w64 via MSYS2, which provides up-to-date native builds of GCC, MinGW-w64, and other helpful C++ tools and libraries. This will provide you with the necessary tools to compile your code, debug it, and configure it to work with IntelliSense.

  1. You can download the latest installer from the MSYS2 page or use this direct link to the installer and open it.
  2. Install it with default settings and check the run MSYS2 now box at the finish page and click finish. Image description
  3. In this terminal install MINGW64 by running this command and press enter. pacman -Syu
    Image description
    then type Y to proceed with the installation.
    and then type Y once again to update confirm all the MSYS2 Processes.

  4. Open Msys2 application from the start menu.
    Image description

  5. Type this command line pacman -Su and press enter. Type Y and enter to proceed with the installation.
    Image description

  6. Paste this command in the terminal.
    pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
    and press enter.
    Image description
    then press enter again and type Y to proceed with the installation.

Step 4: Adding bin to Windows PATH environment variable.

  1. Search Edit environment variables for your account and open it. Image description
  2. Select PATH and click on Edit. Image description
  3. Click on new and enter your path to bin folder. If you used the default settings above, then this will be the path: C:\msys64\ucrt64\bin Image description

Step 5: Check your MinGW Installation.

To check that your MinGW-w64 tools are correctly installed and available, open a Command Prompt and type:

gcc --version
g++ --version
gdb --version
Enter fullscreen mode Exit fullscreen mode

If MinGW is installed correctly you should see the version of your installation.

Image description

That's It, you have successfully installed MinGW and C++ for VS Code.

Top comments (0)