Installing C/C++ Programming Environment

programming Aug 02, 2020

This post illustrates how to set up the Programming Environment for C and C++ languages. To set up our environment, we shall use the GNU Compiler Collection (GCC) and Visual Studio Code as the editor on a Windows 10 device.

GCC Installation

We first need to install the GCC compiler on windows. Since GCC was originally created for GNU operating system, to install it on windows, we need to install Minimalist GNU for Windows (MinGW). The file mingw-get-setup.exe can be downloaded from here.

Follow the on-screen instructions to install MinGW-Get setup. Post completion of installation, on the last screen, press "Quit" instead of "Continue" to exit the setup.

Open a Command Prompt window and type the following to install GCC through MinGW:
mingw-get install gcc g++ gdb

The above command will install the c compiler, c++ compiler and the GNU debugger along with their dependencies, headers and libraries.

In case the command prompt throws a command not recognized error (as below):
'mingw-get' is not recognized as an internal or external command, operable program or batch file.

It means that we need to set the environment path variable for mingw-get or directly run it from source directory. Typically the source directory for mingw-get is: C:\MinGW\bin

Once the installation of gcc, g++, and gdb is finished, we can verify the same through command prompt as following:

  • For GDB:
    >gdb GNU gdb (GDB) 7.6.1 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "mingw32". For bug reporting instructions, please see: <>. (gdb)
  • For G++:
    >g++ g++: fatal error: no input files compilation terminated.
  • And for GCC:
    >gcc gcc: fatal error: no input files compilation terminated.

Getting the above outputs mean that the compilers and debugger for C and C++ have been successfully installed.

Visual Studio Code Installation

Visual Studio Code can be installed from here. Follow the on-screen installation instructions for VS Code. Post installation, we need to add the C/C++ extensions.

  1. Launch VS Code and at the left toggle, click the button for Extensions.
  2. Search for Extensions for C.
  3. Install the Extensions C/C++ by Microsoft and C/C++ Compile Run by danielpinto8zz6


Compiler and Debugger Configuration

We now need to configure the VS code compiler and debugger to use gcc and gdb for compiling and debugging C/C++ files. To do so, we will create three .json files which will act as configuration files for VS Code.

From the top left corner in VS Code, open explorer and navigate to a folder of your choice. Create a new C-code file and add the following:

#include <stdio.h>

int main(void)
    printf("Hello World\n");

Save this program in the folder. This folder will contain your code and output files. Next, we'll create the tasks.json file:

  1. From the top menu bar, goto Terminal -> Configure Default Build Task
  2. Choose Others from the drop down Menu
  3. Add the below code in the drop file:
    // See
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
            "label": "C/C++: gcc.exe build active file",
            "type": "shell",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
            "options": {"cwd": "${workspaceFolder}"},
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true

The "isDefault": true value in the group object specifies that this task will be run when you press Ctrl+Shift+B

Now we'll create the launch.json file to configure VS Code to used gdb debugger.

  1. From the top left corner in VS Code, click on the Run Button.
  2. This will open the run panel. Click on the orange "Run and Debug" button.
  3. In the option choose C++ (GDB/LLDB)
  4. On the next option choose gcc.exe
  5. This will open the launch.json file
  6. Comment out the existing path for miDebuggerPath and replace it with the path of GDB file:
    "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",


That's All Folks!

This should set up your C/C++ programming environment. You can use F5 for debugging and F6 for compiling your code. Visual Studio Code's complete Keyboard Cheatsheet can be found here.

Sreyash Ratna Tripathi

I'm a Cyber Security Professional, Graduate Student at Carnegie Mellon University, and Co-creator of REScure Threat Intelligence Platform.