0

enter image description here

I've been trying to setup C++ on my laptop. I've installed Mingw and the packages. I have the bin path (C:\MinGW\bin) in Path location. I've tried both Path user and system but I still get g++ is not recognized in command prompt. In the terminal of Visual Studio Code, I run g++ --version, I get the correct response. But when running a program, it'll say g++ is not recognized.

CMD PATH C:\MinGW\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Windows\System32\MinGW\bin;C:\Users\drake\AppData\Local\Programs\Python\Python39\Scripts;C:\Users\drake\AppData\Local\Programs\Python\Python39;C:\Program Files\Java\jdk-12.0.1\bin;C:\Users\drake\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\drake\AppData\Local\Microsoft\WindowsApps;C:\Windows\system32;C:\Windows;C:\Windows\system32\Wbem;C:\Windows\system32\WindowsPowerShell\v1.0;C:\Windows\system32\OpenSSH;C:\MinGW\bin;

PowerShell C:\MinGW\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Windows\System32\MinGW\bin;C:\Users\drake\AppData\Local\Programs\Python\Python39\Scripts;C:\Users\drake\AppData\Local\Programs\Python\Python39;C:\Program Files\Java\jdk-12.0.1\bin;C:\Users\drake\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\drake\AppData\Local\Microsoft\WindowsApps;C:\Windows\system32;C:\Windows;C:\Windows\system32\Wbem;C:\Windows\system32\WindowsPowerShell\v1.0;C:\Windows\system32\OpenSSH;C:\MinGW\bin;

EDIT: gcc and g++ only work when I do gcc.exe --version or g++.exe --version. This causes problem with visual studio code because when trying to run the program, it's running with just gcc instead of gcc.exe.

11
  • Side note: If you ever find yourself juggling multiple compilers you may come to regret having built one into the path. Commented Aug 24, 2021 at 23:19
  • That said, could you add the full and complete path string to the question? If it's some thing simple like a typo or missing delimiter we'll be able to knock that out very quickly. You can easily get the path by typing path into a cmd window. Commented Aug 24, 2021 at 23:20
  • Shouldn't "C:\MinGW\bin" be the path string used? It has all the gcc.exe and g++.exe files. Commented Aug 24, 2021 at 23:24
  • 1
    You may need to tell VS Code to use g++. Have a look at this link about setting compilerPath: code.visualstudio.com/docs/cpp/config-msvc#_compiler-path Commented Aug 24, 2021 at 23:25
  • What about cmd not able to run g++ --version? Commented Aug 24, 2021 at 23:33

3 Answers 3

0

there's a couple of things that can cause that

First, make sure that you installed MinGW probably as shown in this picture: 1

second, make sure that in C:\MinGW\bin gcc.exe and g++.exe are located and working probably (run them from the cmd in the same folder)

after that close the cmd if it's opened and try to type gcc or g++

and if it didn't work you can check the PATH by typing echo %PATH% and you C:\MinGW\bin separated by a semicolon

Sign up to request clarification or add additional context in comments.

10 Comments

cmd in the bin folder?
yeah just open it there by shift+right click or by typing cmd in the directory bar
I opened a powershell terminal and ran gcc --version and it worked. But cmd still doesn't work.
Is there any chance my cmd is broken or path is incorrect? Nothing seem to be working for PATH.
can you please send you PATH by using echo %PATH% (for cmd), $env:Path (for powershell)
|
-1

I assume you are doing so to get g++ compiler. And in case you are unable to rectify the problem you can do following:

  1. First of all, install Windows Subsystem for LInux on Windows Features. Reboot.

  2. Install Ubuntu.

  3. Run bash and create a user account with a password.

  4. Make a “sudo apt update” to update the repo packages.

  5. Then you can do “sudo apt install gcc” and “sudo apt install g++”.

  6. Use Remote wsl on VS.

  7. Mnt your files on wsl

2 Comments

he's using windows
@Titoot that's why I mentioned WSL(windows subsystem for Linux), windows included it to let developer run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows.
-1

Turns out the problem was my PATHEXT the whole time. I must have enter a new pathext variable a while ago for some reason and it messed it all up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.