Vscode g++ is not recognized as an internal or external command, operable program or batch file.

I am trying to set up the VScode with C++ Compiler
By following this tutorial
enter link description here

and the problem I got is (By running the code with code runner)

'g++' is not recognized as an internal or external command,
operable program or batch file.
enter image description here

and if I run with the debug option I got this problem

The preLaunchTask 'build & run file' terminated with exit code 1.enter image description here

This is my "c_cpp_properties.json"

{ "configurations": [ { "name": "Win32", "intelliSenseMode": "clang-x64", "defines": [ "_DEBUG", "UNICODE", "__GNUC__=7", "__stdcall=attribute((stdcall))", "__cdecl=__attribute__((__cdecl__))", "__cplusplus=201703L" ], "includePath": [ "${workspaceFolder}/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include" ], "browse": { "path": [ "${workspaceFolder}/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed", "C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include" ], "limitSymbolsToIncludedHeaders": false, "databaseFilename": "" }, "cStandard": "c11", "cppStandard": "c++17" } ], "version": 4

}

This is my "launch.json"

{ "version": "0.2.0", "configurations": [ { "name": "Run C/C++", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW64/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ], "preLaunchTask": "build & run file" }, { "name": "Debug C/C++", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW64/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ], "preLaunchTask": "build & debug file" } ] }

And this is my "tasks.json"

{ "version": "2.0.0", "tasks": [ { "label": "build & debug file", "type": "shell", "command": "g++", "args": [ "-g", "-o", "${fileBasenameNoExtension}", "${file}" ], "group": { "kind": "build", "isDefault": true } }, { "label": "build & run file", "type": "shell", "command": "g++", "args": [ "-o", "${fileBasenameNoExtension}", "${file}" ], "group": { "kind": "build", "isDefault": true } } ] }

I just want to study C++ and I try a lot of way on the Internet for days and I still can't fix it Please help.
Thank you.

The recommended development environment for C++ programming in CPTR 124 and CPTR 318 this semester is Microsoft's Visual Studio Code (VSCode). VSCode is available for free for Microsoft Windows, Apple macOS, and Linux. Many other fine C++ integrated development environments exist for these platforms, but each has its own peculiar way of configuring projects for editing, building, debugging, and executing C++ programs. The process of setting up a C++ project involving external libraries and other dependencies sometimes can become complicated, and it can be tedious to diagnose and correct configuration errors in a multitude of different development systems. Students using VSCode can be assured that they will receive timely support when things are not working as they should.

VSCode is a programming editor coupled with a lightweight project management system. VSCode itself does include the tools necessary for compiling and debugging C++. You must install the C++ development tools (compiler, linker, and debugger) separately and then configure VSCode to use these tools. Fortunately, installing the C++ tools and VSCode and configuring everything to work for our purposes is relatively easy on Windows, macOS, and Linux.

This document explains how to install and configure the necessary C++ development tools and VSCode on Windows, macOS, and Linux.

  • Microsoft Windows

    We will use a slightly enhanced version of Stephan T. Lavavej's distribution of the MinGW C++ compiler. Stephan's website has his current MinGW mix, but you should download and unzip MinGW-124.zip. This remix has an additional graphics library (GLUT) and a slightly modified console batch file to integrate better with VSCode. This MinGW package contains all the tools necessary for command-line development with C++ under Windows.


    Setting Up VSCode for C++ Development

    The following describes the necessary steps to install the VSCode enviroment for C++ development:

    1. Install the MinGW C++ tools.
      1. Download the file MinGW-124.zip.
      2. In a Windows Explorer window, right click on the file and select "Extract All ..." In the ensuing dialog box be sure to type C:\ in the text field that specifies the folder into which the files will be extracted.

        Vscode g++ is not recognized as an internal or external command, operable program or batch file.

        It is important that you use this exact path, or else the VSCode configuration files will not be able to find the C++ toolset.

      3. Test your MinGW tools installation: In an explorer window, double click on the file C:\MinGW\vs_code_terminal.bat. You then should see a console window appear. In the console window at the C:\MinGW> prompt type the command g++ -v:

        C:\MinGW>g++ -v

        (The C:\MinGW> part is prompt provided by the console, and you type only the part that follows.)

        The console window should respond by printing something similar to the following:

        Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/7.2.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../src/configure --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib --prefix=/c/temp/gcc/dest --with-sysroot=/c/temp/gcc/dest --disable-libstdcxx-pch --disable-libstdcxx-verbose --disable-nls --disable-shared --disable-win32-registry --with-tune=haswell --enable-threads=posix --enable-libgomp Thread model: posix gcc version 7.2.0 (GCC) C:\MinGW>

        If instead you see

        'g++' is not recognized as an internal or external command, operable program or batch file. C:\MinGW>

        then something went wrong, and you should ask for help to fix it before continuing with the steps that follow.

      This completes the installation of the MinGW C++ toolset.

    2. Install VSCode.

      Download the VSCode installer (https://code.visualstudio.com/), and install it as you would any other Windows application. It then should appear in your start menu as "Visual Studio Code." You can pin it to your large start menu or to your taskbar for quicker access. Launch VSCode to ensure that it installed correctly. VSCode should display a welcome screen similar to the one as shown here:

      Vscode g++ is not recognized as an internal or external command, operable program or batch file.

      We are not quite ready to start C++ programming, but we almost are there.

      This completes the installation of VSCode.

    3. Work with the sample C++ project.
      1. Download the archived sample C++ project, firstprogram.zip. Unzip the firstprogram.zip file. This creates a folder named FirstProgram, and in that folder you will find two files and and subfolder:
        • starter.cpp contains the source code for a very simple C++ program.
        • Makefile is a configuration file that specifies how to build the executable program from the source file.
        • .vscode is a folder that contains several files that allow VSCode to work properly with the MinGW C++ toolset.

        The file starter.cpp contains the following C++ program:

        #include <iostream> int main() { std::cout << "Our first C++ program\n"; }

      2. Launch VSCode. In the File menu, select "Open Folder ..." and navigate to the FirstProgram folder you just downloaded and unzipped. Direct VSCode to open this FirstProgram folder.

      3. From the VSCode Explorer pane on the left you can open the starter.cpp source file in a editor by double-clicking on it.

      4. You can build and run the program as follows:
        1. Hold down the Shift and Ctrl keys and press the C key. This brings up a console window.
        2. In the console window type the command make run. This command will attempt to build the executable program from the source file, and, if it is successful, it will run the program.

        3. The program should print

          Our first C++ program

    In summary, the following three steps set up VSCode for C++ development under Microsoft Windows:

    1. Unzip the custom MinGW.zip archive into C:\
    2. Install VSCode
    3. Obtain a copy of an existing working C++ VSCode project folder

    You need do these three set-up steps only once.

    That is all there is to setting up VSCode for C++ development. Next we examine the typical workflow for creating a new C++ project.


    Using VSCode

    After you have created your first C++ project, creating another one is very simple. To see how simple it is, let's create a new VSCode C++ project and supply our own C++ program.

    You will follow steps similar to the following each time you want to write a C++ program using VSCode:

    1. Copy the folder and its contents of an existing VSCode C++ project. Since we currently have only one VSCode C++ project (FirstProgram), use Window Explorer to make a copy of the FirstProgram folder. For the sake of this exercise, name it SecondProgram.

    2. Open the copied folder in VSCode. In this case open the SecondProgram folder in VSCode. At this point it is an exact copy of the original project, FirstProgram.

    3. Rename the C++ source file. Since this is a new program it is a good idea to give the source file a different name. Right click on starter.cpp in VSCode's Explorer pane. Select "Rename" to change the file's name to secondprogram.cpp.

      (This step technically is not necessary. Since each C++ source file will be in its own project folder, the source files could all have the same name. For example, program.cpp in the project folder Project1 could be an entirely different program than in the file program.cpp in the Project2 project folder.)

    4. Edit the Makefile. The Makefile is designed to work with the original project, and we need to make a small change to adapt it to this new project. The Makefile is expecting a C++ source file named starter.cpp, but we just renamed it to be secondprogram.cpp. Open Makefile in the VSCode editor. Change the first line from

      PROGNAME = starter.cpp

      to

      PROGNAME = secondprogram.cpp

      (Note that this step is unnecessary if you did not rename the source file in the previous step.)

    5. Edit the C++ source file. We want our new program in this SecondProgram to behave differently from the one in our FirstProgram project. Edit the secondprogram.cpp file so that it will display the following output when executed:

      *** This is our second C++ program! ***

    6. Build and run the program. Bring up a VSCode console window (press Shift + Ctrl + C) and type make run. If the program does not build properly or does run as expected, return to the VSCode editor and make changes to the source code to fix build errors and/or correct the program's errant behavior. It may take many edit-build-run cycles to achieve the finished product that runs correctly.

    Summary

    In summary, the following three steps set up VSCode for C++ development under Microsoft Windows:

    1. Unzip the custom MinGW.zip archive into C:\
    2. Install VSCode
    3. Obtain a copy of an existing working C++ VSCode project folder

    You need do these three set-up steps only once.

    Once set up, the following three steps create a new C++ project in VSCode:

    1. Copy an existing working C++ VSCode project
    2. Rename the C++ source file (optional but advisable)
    3. Edit the first line of the Makefile to reflect the C++ source file's new name (not necessary if you skipped Step 2)
    4. Edit the C++ source file to implement the desired program

    You perform these four steps every time you wish to write a new program using VSCode.

    To build and run a C++ program under VSCode, bring up a VSCode console window (press Shift + Ctrl + C) and type make run. Repeat the edit-build-run sequence until the program behaves correctly.

How do you fix G ++' is not recognized as an internal or external command operable program or batch file?

After downloading, install MinGW and wait for the “MinGW Installation Manager” to show up..
When the “MinGW Installation Manager” shows up, click on mingw32-gcc-g++ then select “Mark for Installation”.
In the menu at the top left corner, click on “Installation > Apply Changes”.
Wait and allow to install completely..

How do I fix G + is not recognized as an internal?

You need to set the environment PATH to include the directory of mingw's bin directory if you want o use gcc.exe or g++.exe in cmd . run 'path' or 'echo %PATH% in cmd.exe prompt.

Why G ++ is not recognized VS Code?

If you don't see the expected output or g++ or gdb is not a recognized command, make sure your PATH entry matches the Mingw-w64 binary location where the compilers are located. If the compilers do not exist at that PATH entry, make sure you followed the instructions on the MSYS2 website to install Mingw-w64.