Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

g++

mingw

Visual Studio Code cannot find the g++ command of my MinGW(btw, intelliSense has no problem because I have set c_cpp_propertites.json correctly). Any idea? Thanks in advance, the following is the output:

Executing task: g++ -g helloworld.cpp

g++ : The term 'g++' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

like image 768
adorp Avatar asked Oct 12 '17 20:10

adorp


People also ask

Why is G ++ not recognized VS Code?

If you don't see the expected output or g++ or gdb is not a recognized command, make sure your PATH entry matches the Mingw-w64 binary location where the compilers are located. If the compilers do not exist at that PATH entry, make sure you followed the instructions on the MSYS2 website to install Mingw-w64.

How do I add G ++ code to Visual Studio?

From the main menu, choose Terminal > Configure Default Build Task. A dropdown appears showing various predefined build tasks for C++ compilers. Choose C/C++: g++ build active file.

Does MinGW contain g ++?

Gcc distributions such as mingw provide a gcc executable which can be used to compile files in any language the distribution supports. They also provide other compiler drivers, which in the case of mingw are executables such as g++, c++, g77, etc.


2 Answers

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.

like image 101
Yiming Lu Avatar answered Sep 24 '22 05:09

Yiming Lu


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++.

like image 44
Ben Arceneaux Avatar answered Sep 23 '22 05:09

Ben Arceneaux