6

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
S.Xu
  • 173
  • 2
  • 3
  • 11
  • 3
    Possible duplicate of ['g++' is not recognized as an internal or external command, operable program or batch file](https://stackoverflow.com/questions/38652211/g-is-not-recognized-as-an-internal-or-external-command-operable-program-or) – Ken White Dec 30 '18 at 04:01
  • Re `"command": "g++"`, you may want to include the full location (including directory) there, unless you're sure the directory that contains it actually *is* in your standard path. – paxdiablo Dec 30 '18 at 04:12
  • Ken White That post doesn't help me out. – S.Xu Dec 30 '18 at 07:18
  • Does this answer your question? ["g++" is not recognized as an internal or external command, MinGW](https://stackoverflow.com/questions/9741568/g-is-not-recognized-as-an-internal-or-external-command-mingw) – Donald Duck Nov 22 '20 at 12:56

4 Answers4

5

You have to add g++ to your PATH variable.

First, find out if you have installed g++ and find where it is located.

You have not mentioned what OS you are using. If you are using Windows, it may be located in C:\mingw or C:\Program Files\mingw.

If you haven't installed g++, you can install it via https://sourceforge.net/projects/mingw-w64/

Then open System Properties -> Advanced -> Environment Variables.

Then under Environment Variables for <username> choose PATH and click on Edit.

Click on New and then click on Browse and find the bin directory in your mingw installation and add that to the path and you're done.

Restart VSCode if you have it open and it would automatically find g++.

Saurabh Sangpal
  • 101
  • 2
  • 7
  • 3
    Given they're using MinGW (Minimalist GNU for ***Windows***), it's a reasonably safe bet they're on Windows :-) – paxdiablo Dec 30 '18 at 04:15
2

[Sloved] I had the same problem and I solved it:

Simply add a new path as: "C:\MinGW\bin\g++.exe"
Now reopen your VS code and you are done:

enter image description here

0

You have to add mingw.

First, find out if you have installed g++ and find where it is located.

  1. First copy mingw file in c drive. mingw download link: https://drive.google.com/file/d/112lN_esKLgOJ-bXbw7iGgbTOU5wKfW-_/view?usp=sharing 1

  2. If you are using Windows, it may be located in C:\mingw\bin .

2

  1. Then open System Properties -> Advanced -> Environment Variables -> Edit

3

  1. Then click New -> paste the link C:\mingw\bin then OK.

4

  1. Restart VSCode if you have it open and it would automatically find g++
Shahriar Hossain
  • 119
  • 2
  • 13
  • 2
    Did you post a link to your personal copy of the mingw installer? Why not post a link to the official [mingw ](http://www.mingw.org/) page? – JarMan Sep 01 '20 at 20:32
  • 1
    Not a good idea. I wouldn't trust an executable that didn't come from an official source. – JarMan Sep 02 '20 at 13:24
0

First, open this page and install and Configure Mingw on your System:

http://www.mingw.org/wiki/getting_started

after download and install, you must Add Mingw->bin to your paths with this Link:

https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

then to ensure, type g++ --version in CMD or gcc --version

then you can use this Link for Your purpose.

for more help, use

https://code.visualstudio.com/docs/cpp/config-mingw

this Link probably is very useful for you

sakiM
  • 4,832
  • 5
  • 27
  • 33
MohammadHossein
  • 51
  • 1
  • 3
  • 12
  • It is better to avoid passing external links in an answer. If you are going to refer to external resources, please also give an outline of what is described in the external reference you are referencing. – Patrick Nov 11 '20 at 06:04