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.
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.
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.
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.
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++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With