Visual Studio Code cannot find the g++ command of my MinGW-w64

The temporary solution for this problem is as follows :---

  1. Open VsCode in Run as administrator .
  2. And set your tasks.json as follows. For ex :-- If your file name is main.cpp

Tasks.json

It will build the file without error.


I've just had the same problem. Adding the \mingw\bin folder to my PATH variable didn't help. Running g++ in a cmd or PS window worked without a problem so it seems like VSCode is having problems reading or resolving the PATH variable.

To bypass this problem I've included the complete path to g++.exe in the command property of my task. After saving the task, VSCode was able to build my .cpp file.

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build g++",
            "type": "shell",
            "command": "C:\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": ["-g", "-o", "${fileBasenameNoExtension}", "${fileBasename}"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

What happened to me was that VSC didn't automatically source my PATH. After I added g++, closed and reopened it, the issue was solved.


I'm having a similar issue and I believe I've narrowed it down to being due to "g++" being your command. Check your task config file and note what you have set for "command".

"command" is what the task is going to try and run along with whatever arguments you have stipulated which in your case I assume is "-g" and "helloworld.cpp".

Now, what I'm having trouble determining is why it isn't finding g++ as if I try to compile a source file via a command prompt I have no issue and it compiles successfully.

Looking through the documentation for VS code I did find a way to reference your environment variables in the task config: {env:Path} will serve as prefix for my User environment variable "Path" which has a reference to c:\Mingw\lib\bin (note this is an accurate path, simply an example). I think we're pretty close to getting it to work it's just a matter of pathing to g++. My next attempt I think I will simply change "command" to reference an absolute path to g++.

Tags:

Mingw

G++