'g++' is not recognized as an internal or external command, operable program or batch file.
Solution 1
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++.
Solution 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:
S.Xu
Updated on January 22, 2022Comments
-
S.Xu over 2 years
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 over 5 years
-
paxdiablo over 5 yearsRe
"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. -
S.Xu over 5 yearsKen White That post doesn't help me out.
-
Donald Duck over 3 yearsDoes this answer your question? "g++" is not recognized as an internal or external command, MinGW
-
-
paxdiablo over 5 yearsGiven they're using MinGW (Minimalist GNU for Windows), it's a reasonably safe bet they're on Windows :-)
-
JarMan over 3 yearsDid you post a link to your personal copy of the mingw installer? Why not post a link to the official [mingw ](mingw.org) page?
-
JarMan over 3 yearsNot a good idea. I wouldn't trust an executable that didn't come from an official source.
-
Patrick over 3 yearsIt 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.