我正在尝试使用C ++编译器设置VScode 通过遵循本教程 enter link description here
我遇到的问题是(通过使用代码运行器运行代码)
'g ++'不被识别为内部或外部命令, 可操作的程序或批处理文件。 enter image description here
如果我使用debug选项运行,则会遇到此问题
preLaunchTask“构建和运行文件”以退出代码1终止。enter image description here
这是我的“ 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
}
这是我的“ 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"
}
]
}
这是我的“ 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
}
}
]
}
我只想学习C ++,我在Internet上尝试了很多天,但仍然无法解决它,请帮忙。 谢谢。
答案 0 :(得分:0)
您必须将g ++添加到PATH变量中。
首先,确定是否已安装g ++并找到它的位置。
您尚未提到正在使用的操作系统。
如果您使用的是Windows,则它可能位于C:\mingw
或C:\Program Files\mingw
中。
如果尚未安装g ++,则可以通过https://sourceforge.net/projects/mingw-w64/
安装然后打开System Properties -> Advanced -> Environment Variables
。
然后在Environment Variables for <username>
下选择PATH
,然后单击“编辑”。
单击“新建”,然后单击“浏览”,然后在mingw安装中找到bin
目录,然后将其添加到路径中,即可完成操作。
如果打开VSCode并重新启动,它将自动找到g ++。
答案 1 :(得分:0)
答案 2 :(得分:0)
您必须添加mingw。
首先,确定是否已安装g ++并找到它的位置。
首先在C驱动器中复制mingw文件。 mingw下载链接:https://drive.google.com/file/d/112lN_esKLgOJ-bXbw7iGgbTOU5wKfW-_/view?usp=sharing 1
如果您使用Windows,则它可能位于C:\ mingw \ bin中。
答案 3 :(得分:0)
首先,打开此页面并在系统上安装并配置Mingw:
http://www.mingw.org/wiki/getting_started
下载并安装后,必须使用此链接将sheet
添加到您的路径中:
https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/
然后确保在CMD中输入Mingw->bin
或g++ --version
然后您就可以使用此链接了。
要获取更多帮助,请使用
https://code.visualstudio.com/docs/cpp/config-mingw
此链接可能对您非常有用