如何在Windows 10 VS Code上为C++设置tasks.json和c_cpp_properties.json后修复" /bin/bash:找不到[命令]命令"?



我已经配置了task.json和c_cpp_properties.json,这样我就可以编译我的main.cpp程序了。为了继续,我必须按下

Ctrl + Shift + B

我一这么做,就会弹出一个终端,并更改我的错误:

Executing task in folder C++: C:MinGWbing++.exe -g main.cpp -o c:UsersMeDesktopC++.vscodetasks.exe <
/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.

我不知道为什么会发生这种情况,因为我已经检查了MinGW是否安装在我的计算机中,路径是否正确。为了确保我这样做,我在终端中键入了以下内容:

g++ --version
g++ (MinGW.org GCC-8.2.0-3) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.

我还根据这个图检查了路径

唯一与我最相关的问题是在这个Github链接中。我也已经尝试使用这个线程更改下面代码中显示的文件目录,但我仍然遇到这个错误。

以下是我的JSON文件,它们位于.vscode文件中:

tasks.json:

{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "C:\MinGW\bin\g++.exe",
"args": [
"-g",
"main.cpp",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}

c_cpp_properties.json:

{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\MinGW\lib\gcc\mingw32\8.2.0\include\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}

我应该期望在编译后看到一个".exe",但由于错误,我不能。

在花了两天时间处理这个问题之后,我终于能够在VS Code上更正C++设置并解决了这个错误。

根据上面的png图片,我在对话框"user variables for Me"下的用户变量"Path"中包含了"C:\MinGW\bin"。在我的电脑上简单地重新启动后,我能够毫无问题地构建我的项目(Shift+Ctrl+B)。

最新更新