Vscode-cpptools: g++ not recognized as the name of a cmdlet

Created on 11 Dec 2017  Â·  64Comments  Â·  Source: microsoft/vscode-cpptools

Hi I have some issue in order to debbug C++ with visual studio code.
I followed this tutorial : https://code.visualstudio.com/docs/languages/cpp

I'm using Visual Studio Code 2017 on windows 10.

Could you please help me, it has been at least a week and I still didn't find the issue.

Cheers.
2
1
3


EDIT: The most upvoted answer is here, though you should really just need to update your PATH environment variable to include C:\MinGW\bin (or whatever the path to your compiler is) and then restart VS Code.

builtasks external question

Most helpful comment

Close the visual studio and reopen it by right clicking on it and selecting run as administrator. I had similar problem and this worked for me

All 64 comments

You need to install g++/gcc somehow, or install a different compiler, such as cl.exe or clang. I just use "sudo apt-get install g++" on Ubuntu, but I haven't installed g++ that on Windows. I assume the mingw docs would explain how to install the gcc compiler. Are you able to install a C++ compiler?

I already installed MinGW as a compiler and I have the files gcc.exe and g++.exe.
But I don't know why VS code couldn't find it and gives me this error.

Is g++ on your PATH? If you type g++ on the command line it should give an output message from it.

Yes I think so, is this the right path ?
1

Okay, I've reproed the problem. I'm not sure why VS Code isn't picking the environment path or what path it's using, because it picks up my CMake directory somehow, but not my MinGW directory. I was able to fix this via using the full path to g++ in the command. Does that work for you? You could also file a complaint with https://github.com/Microsoft/vscode/issues . There might be some way to get the correct environment path to be used, but I don't know what it is. I don't have this problem on Linux, only on Windows, which is using PowerShell on the terminal.

Now I have another issue, it is saying that :

'g++' is not recognized as an internal or external command,
operable program or batch file.
The terminal process terminated with exit code: 1

That sounds like the same error, but coming from cmd.exe instead of powershell. Can you use the full path to g++?

How can I change that ?

On Dec 11, 2017 3:19 PM, "Sean McManus" notifications@github.com wrote:

That sounds like the same error, but coming from cmd.exe instead of
powershell. Can you use the full path to g++?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-cpptools/issues/1329#issuecomment-350891027,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ag1qjgoWXx62bTT5yqRzm9tMkhGmagBfks5s_biGgaJpZM4Q86c_
.

Change the command property to from "g++" to "C:/MinGW/bin/g++".

Sorry to bother you with that, but I still didn't find the answer

[image: Images intégrées 1]
On Dec 11, 2017 4:12 PM, "Sean McManus" notifications@github.com wrote:

Change the command property to from "g++" to "C:/MinGW/bin/g++".

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-cpptools/issues/1329#issuecomment-350901167,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ag1qjhEHYhooLz6bIESI9mIQpuEFmYBDks5s_cTxgaJpZM4Q86c_
.

That's fine. Is it working now?

No I send you a screenshot,

my terminal is saying that :

Executing task: C:\MinGW\bin\g++ -g helloworld.cpp <

The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

2017-12-11 16:26 GMT-08:00 Sean McManus notifications@github.com:

That's fine. Is it working now?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-cpptools/issues/1329#issuecomment-350903430,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ag1qjqdYGUOciXFGE2wOBdWGBLtdpJJEks5s_cgagaJpZM4Q86c_
.

Yeah, I'm getting the same error you're getting. It's strange that there's no detailed error message, even with the -v flag. I'll ask around to see if anyone know about this.

thanks for reopening that.

Can either of you confirm the version of G++ you are using? Also, if you run it in the command window, you have to make sure to set the PATH to your MinGW bin folder first. This is a limitation of MinGW because it needs to know where its libraries are that it needs during compilation.

You should be able to run SET PATH=%PATH%;<path to your mingw bin folder> and then run your G++ command. Alternatively you can set that path from a command prompt and then launch VS Code from the same command prompt.

I'm using the 6.3.0-1 version, the one I got with mingw.

On Dec 12, 2017 11:52 AM, "Pierson Lee" notifications@github.com wrote:

Can either of you confirm the version of G++ you are using? Also, if you
run it in the command window, you have to make sure to set the PATH to your
MinGW bin folder first. This is a limitation of MinGW because it needs to
know where its libraries are that it needs during compilation.

You should be able to run SET PATH=%PATH%;
and then run your G++ command. Alternatively you can set that path from a
command prompt and then launch VS Code from the same command prompt.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-cpptools/issues/1329#issuecomment-351174063,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ag1qjmV9oLq6DKJoiNkVldADwp_f5-GKks5s_tlsgaJpZM4Q86c_
.

I'm using 5.3.0. ${env:Path} is showing that F:MinGW\bin is on the path, but the path isn't recognized if I remove the path from the beginning of gcc. @pieandcakes can you post the command line you're using?

@sean-mcmanus The comment I made is not to fix the issue of finding gcc in the path, it is to help gcc resolve dependencies it needs during compile time.

I compile from a command window, not through VS Code task.json. I assume if you want to use the task.json implementation, to create a .cmd file that sets the path and then issues the compile command.

Note: This sounds like a toolchain issue with MinGW and not an issue with the extension.

I tried to type in the terminal too, and still didn't manage to make it work.

@regunHD

I tried to type in the terminal too, and still didn't manage to make it work.

Did you try this in a MinGW command window or a regular command window or VS Code's terminal window? The last two do not have the correct path set so it won't resolve dependencies. One of the other suggestions I've heard is to try MSYS2's version of MinGW.

Sorry, I don't really know to do that, I'm actually new in this software.
Since I'm using windows how can I have access to the terminal.

@regunHD

Sorry, I don't really know to do that, I'm actually new in this software.
Since I'm using windows how can I have access to the terminal.

If you are talking about the MinGW terminal, you can see if it is in one of the installed programs on your machine? Otherwise, it would be a normal command prompt but you would need to set the path as above.

Ok then. I don't have it installed, and I couldn't find it on my MinGW installer program.

Should I install it with a .exe installer (since I'm using windows 10) ?

https://blogs.msdn.microsoft.com/vcblog/2017/07/19/using-mingw-and-cygwin-with-visual-cpp-and-open-folder/ is a blog post that should help you get started on how and where to install MinGW from. I think this article links to MSYS2 which will work also.

Close the visual studio and reopen it by right clicking on it and selecting run as administrator. I had similar problem and this worked for me

@priyamadhu I had to read all the way down here after trying everything above only to find out that your suggestion worked. Thanks mate.

getting 'The terminal process terminated with exit code: 1' .
tasks.json
{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "C:/raylib/mingw/bin/gcc.exe", "args":[ "-g", "hi.c" ], "group": { "kind": "build", "isDefault": true } } ] }

c_cpp_properties.json:

{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.17134.0", "compilerPath": "C:/raylib/mingw/bin/gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "msvc-x64" } ], "version": 4 }

@liamsain Can you look in your output window and see what the error message is? Also, from a regular command prompt can you run your command and see if you get more info?

output window is empty. If I run from the command prompt I get an error window, title 'cc1.exe - System Error', message: 'The code execution cannot proceed because libwinpthread-1.dll was not found. Reinstalling the program may fix this problem'. Guess it's not a vscode-cpptools issue..

@liamsain When I've run into that, the problem is that the MinGW bin folder wasn't on the path so it couldn't resolve dependencies. I usually add it to the PATH environment variable and it fixes the problem.

You are correct though. That error is because of a toolset configuration issue and not a vscode-cpptools issue.

@regunHD I was facing the same problem initially. Then I realized that in my system, I had added path to my user's environment variable instead of system's environment variable. As a result even though g++ was recognized in CMD, it was not getting recognized in Powershell.

So after adding path to MinGW bin folder to System's path, it started working

@indrajitsg You are right add the MinGW path to system path and restart the command line interface MinGW compiles flawlessly in all cmd, Powershell and VScode integrated terminal.
@pieandcakes @liamsain Confirmed not a vscode-cpptools issue. On Linux and WSL (xfce) MinGW run smoothly with vscode-cpptools.
@regunHD Alternatively, you can use Chocolatey to install MinGW like this tutorial https://www.youtube.com/watch?v=xW6JTqRuQx0&t=

@liamsain I was facing the same issue, with the help of this issue thread.
-> I added the g++ to the path
-> tried running on my cmd, which worked, but could not get it running on the VS's terminal.
-> then i changed 2 things
"version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "E:\\MinGW\\bin\\g++.exe", "args": ["-g", "main.cpp"], "group": { "kind": "build", "isDefault": true } } ]

instead of "command": "g++", i added the respective code
then i changed terminal to launch in VS code.
you change it from User settings -> Features -> Terminal , there the first option change it to external.
and everything works for me!
thanks!

Close the visual studio and reopen it by right clicking on it and selecting run as administrator. I had similar problem and this worked for me

This actually worked :D

run as administrator!!! Thank you!!!

Close the visual studio and reopen it by right clicking on it and selecting run as administrator. I had similar problem and this worked for me

Thank You :)

Thanks for sharing, administrator worked for me too :)

Close the visual studio and reopen it by right clicking on it and selecting run as administrator. I had similar problem and this worked for me

Really, Microsoft should put your answer in front line 💯

@regunHD What worked for me was adding the file path to the git bash shell (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git) to the System Environment Variables in the Control Panel (how to do that here. Then restart VS Code and it should work. Also, check out this page, it helped me sort things out (read it carefully). If you have any other trouble, take a look at this tutorial. Hope this helps!

Note: in the docs page I linked, they use the 64bit version of MinGW. It should still work with the 32bit version though.

Close the visual studio and reopen it by right clicking on it and selecting run as administrator. I had similar problem and this worked for me

It worked

It worked!Can anyone explain why?I am so crazy about this problem!

I got it working by running as administrator, but the actual problem was that the path was only set for my user and not the system, which has been mentioned by others.

I just used this guide to copy the path for MinGW from my user's Path variable to the system's Path variable.

Once that's done, it works perfectly.

@priyamadhu Thank you for such a precise answer. Though I would want to know the after math

I got it working by running as administrator, but the actual problem was that the path was only set for my user and not the system, which has been mentioned by others.

I just used this guide to copy the path for MinGW from my user's Path variable to the system's Path variable.

Once that's done, it works perfectly.

Worked perfectly for me too.
Thanks everyone!

ps: One might wonder if going through this hassle is really a necessary component of an IDE installation in the 21st century?

@Fenytestver Its a toolset issue. I would expect that if MinGW needs to be on path that they will add it. The other option is to launch MinGW's bash window and run VS Code from there which will inherit the lib path.

Solution that worked for me is:
1) open the folder where you have created the file in which you are writing the code.
2) there you'll see a folder .vscode, open it and there will be a file named c_cpp_properties.json, open that file.
3) now copy the path of your compiler in front of compilerPath(change \ to / if needed) and save the file. (eg: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin)
You are good to go now.
compilerPath_error

I was facing this issue on windows.
The issue was the path in User variables for ${USER} was C:\Mingw\mingw32\bin
and path in System variables was C:MinGW\bin

I resolved it by adding C:MinGW\bin in User variables for ${USER}

https://www.youtube.com/watch?v=xj-A3REo2SY

This video shows everything, about how to instal and use MinGW on windows

When I try to build, I get this error. Can someone help me with this..?

Executing task in folder C project: F:MinGW\bingcc.exe -g 'c:\Users\Muntasir\Desktop\Projects\C project\main.c' -o 'c:\Users\Muntasir\Desktop\Projects\C project\main.exe' <

/usr/bin/bash: F:MinGWbingcc.exe: command not found
The terminal process terminated with exit code: 127

@Muntasir2001 You are confusing MinGW and WSL. You can use WSL which is Linux tools running inside WSL, or MinGW which is running on Windows itself. Your error message below is telling me you are trying to run your MinGW path in WSL:

/usr/bin/bash: F:MinGWbingcc.exe: command not found

I can tell this because it is running the command in /usr/bin/bash

@Muntasir2001 You are confusing MinGW and WSL. You can use WSL which is Linux tools running inside WSL, or MinGW which is running on Windows itself. Your error message below is telling me you are trying to run your MinGW path in WSL:

/usr/bin/bash: F:MinGWbingcc.exe: command not found

I can tell this because it is running the command in /usr/bin/bash

@pieandcakes , Ok I found out the issue. I am using Git terminal as a default terminal for VS code. That's why it was not working with mine. It was able to compile manually though.
Anyway, Thank You

This issue has been answered and the original post has been updated to locate the answer more quickly. Closing.

I have the exact same issue, Tried solutions here and it's not working though.

I tried :

  • Add MinGW/bin folder to System variables
  • Restart VSCode
  • Restart Windows
  • Run VSCode as administrator

g++ is recognized by cmd , Windows PowerShell. But not VSCode's PowerShell Terminal.

Running $env:path dumps the environmental paths, but MinGW/bin isn't one of them.

In the counterpart in Windows PowerShell : It only shows MinGW/bin as an env path.

image

@HamzaHajeir Try adding your path to user variables as well. I installed mingw and vscode and made sure the path was in both. VSCode with C/C++ plugin installed is working seamlessly .

There is a VSCode issue that might be relevant to what you are running into.

@HamzaHajeir Try adding your path to user variables as well. I installed mingw and vscode and made sure the path was in both. VSCode with C/C++ plugin installed is working seamlessly .

That's already added,.

As I'm not fully absorbed the PATH concept, could something be wrong here ?

image

@pieandcakes Thanks for reference, But mine is a bit different, As it didn't work even after a restart (actually .. it was shut down - power on)

Those are all supposed to be inherited by VS Code. You may want to start an issue there about the $env:path variable not showing the correct path values and see what they say.

Thanks, Submitting issue guide got me in trouble : As After I disabled all extensions. then only 2 env path variables shown. instead of many variables (before disabling).. thus my extension (PlatformIO) was no longer recognized even after enabling.

The solution to this second issue is : appending its path to system variables.

Now it's recognized and works well.

Solution that worked for me is:

  1. open the folder where you have created the file in which you are writing the code.
  2. there you'll see a folder .vscode, open it and there will be a file named c_cpp_properties.json, open that file.
  3. now copy the path of your compiler in front of compilerPath(change \ to / if needed) and save the file. (eg: C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin)
    You are good to go now.
    compilerPath_error

I'm sorry, copy it and paste it to where?

Change the command property to from "g++" to "C:/MinGW/bin/g++".

Thanks for the help it helped me a lot

g++ is not recognized in build task.
Capture

g++ is not recognized in build task.
Capture

It seems you've missed installing Git in your system.

https://www.youtube.com/watch?v=xj-A3REo2SY

This video shows everything, about how to instal and use MinGW on windows
Its works for me. Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bobbrow picture bobbrow  Â·  70Comments

TurboTim picture TurboTim  Â·  77Comments

DigiAngel picture DigiAngel  Â·  79Comments

pbnjay picture pbnjay  Â·  75Comments

tinganho picture tinganho  Â·  142Comments