简体   繁体   中英

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?

I have configured my task.json and c_cpp_properties.json so that I may compile my main.cpp program. In order to proceed, I must press

Ctrl + Shift + B

As soon as I do a terminal pops up and alters me of an error:

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.

I don't why this is happening since I've already checked that MinGW is installed in my computer with the correct PATH. To ensure that I do I typed the following in the terminal:

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

I also checked the path according to this figure

The only closest problem related to mine is in this Github link. I've also already tried changing the file directory shown in the code below using this thread but I still encounter this error.

Here are my JSON files which are inside my .vscode file:

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
}

I should expect to see a ".exe" after compiling but I can't due to the error.

After spending two days messing around with this I've finally able to correct setup C++ on VS Code and resolved the error.

According to the png image from above, I've included "C:\\MinGW\\bin" within the user variable "Path" under the dialogue box "User variables for Me". After a simple restart on my computer, I was able to build my project (Shift + Ctrl + B) with no problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM