Reputation: 183
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.
Upvotes: 6
Views: 87566
Reputation: 175
[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:
Upvotes: 3
Reputation: 96
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
Upvotes: 1
Reputation: 148
You have to add mingw.
First, find out if you have installed g++ and find where it is located.
First copy mingw file in c drive. mingw download link: https://drive.google.com/file/d/112lN_esKLgOJ-bXbw7iGgbTOU5wKfW-_/view?usp=sharing 1
If you are using Windows, it may be located in C:\mingw\bin .
Upvotes: 0
Reputation: 101
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++.
Upvotes: 5