在Windows 10 VS Code上为C ++设置task.json和c_cpp_properties.json后,如何修复“ / bin / bash:[命令]命令未找到”?

时间:2019-06-17 19:55:04

标签: json visual-studio-code

我已经配置好task.json和c_cpp_properties.json以便编译main.cpp程序。为了继续,我必须按

Ctrl + Shift + B

一旦我这样做,就会弹出一个终端,并改变我的错误:

Executing task in folder C++: C:\MinGW\bin\g++.exe -g main.cpp -o c:\Users\Me\Desktop\C++\.vscode\tasks.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是否以正确的PATH安装在计算机中。为了确保执行此操作,我在终端中输入了以下内容:

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

我还根据此figure

检查了路径

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

这是我的.vscode文件中的JSON文件:

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”,但由于错误而无法。

1 个答案:

答案 0 :(得分:0)

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

根据上面的png图像,我在对话框“我的用户变量”下的用户变量“路径”中包含了“ C:\ MinGW \ bin”。在计算机上重新启动后,我可以毫无问题地构建项目(Shift + Ctrl + B)。