【问题标题】:How to fix "/bin/bash: [command] command not found" after setting up tasks.json and c_cpp_properties.json for C++ on Windows 10 VS Code?如何在 Windows 10 VS Code 上为 C++ 设置 tasks.json 和 c_cpp_properties.json 后修复“/bin/bash: [command] command not found”?
【发布时间】:2019-06-17 19:55:04
【问题描述】:

我已经配置了我的 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”,但由于错误而我看不到。

【问题讨论】:

    标签: json visual-studio-code


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-21
      • 2019-07-07
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 2019-12-09
      • 2014-02-08
      • 2019-06-27
      相关资源
      最近更新 更多