-2

I installed the MinGW Compiler but when I type g++ in cmd, it just tells me that it's not recognized. But it is RECOGNIZED in every IDE/programming app I tried.

I'm sorry if this is another not-recognized question, but none of the solutions I found on the Internet worked.

H_Henry
  • 3
  • 4
  • 2
    Is the `%PATH%` set correctly? – πάντα ῥεῖ Apr 15 '22 at 12:42
  • Check your OS PATH environment variable. – drescherjm Apr 15 '22 at 12:42
  • ***I installed the MinGW Compiler*** I recommend that you use msys2 to do that: [https://www.msys2.org/](https://www.msys2.org/) with msys2 you get a mingw version that is current with gcc 11.2 and you also have a package management tool pacman that can help you install the proper binaries for thousands of libraries. – drescherjm Apr 15 '22 at 12:44
  • ***I'm sorry if this is another not-recognized question, but none of the solutions I found on the Internet worked.*** Solving the problem requires you to know how your OS runs programs from the command line. Specifically where your OS looks for the binaries. If you updated your PATH environment variable to contain the bin folder of your mingw install try to logout and log back in. Changing an environment variable in the OS does not effect running programs which include your OS explorer which you run your cmd.exe from. – drescherjm Apr 15 '22 at 12:51
  • _"but none of the solutions I found on the Internet worked"_ I'm curious how you searched, considering the duplicate can be found by copy-pasting the error message verbatim. – Passer By Apr 15 '22 at 13:09
  • Please take a look on [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/a/41461002/3074564) It explains in full details the `PATH` management. IDEs redefine their __local__ `PATH` to include the directory(directories) containing the binaries of the compiler(s). – Mofi Apr 15 '22 at 14:26
  • Click on Windows __Start__ button, type on keyboard __environment__ and Windows suggests the items __Edit environment variables for your account__ and __Edit the system environment variables__ in language of Windows. Click on one of these two items and check __user__ and __system__ `Path` if you of these two environment variables contain the directory `bin` of installed *MinGW*. Please note that you best restart Windows do get the change of __user__ or __system__ `Path` applied to all processes. – Mofi Apr 15 '22 at 14:30
  • Much better would be __not__ adding the *MinGW* path to __system__ or __user__ path and use instead a special shortcut file to start the Windows Command Processor for working with *MinGW*. Browse in Windows File Explorer to `C:\Windows\System32\cmd.exe`, right click on this file and clicked in the opened context menu in submenu __Send to__ on the item __Desktop (create shortcut)__. On your Windows Desktop is now the shortcut file with name `cmd.exe.lnk` whereby the file extension `.lnk` is not displayed by Windows. Right click on this file and use __Rename__ to change the name to `MinGW CMD`. – Mofi Apr 15 '22 at 14:35
  • The right click once again on the shortcut file with new name `MinFW CMD` and click on last item __Properties__. There must be modified the property __Target__ from `C:\Windows\System32\cmd.exe` to `C:\Windows\System32\cmd.exe /D /K set "PATH=C:\MinGW\bin;%PATH%"`. I recommend to change also __Start in__ and enter here the directory containing the C/C++ files you want to compile. You can assign a shortcut key to be able to use this shortcut file at any time from within any application on pressing this shortcut key. You can change font, font size, number of rows and columns, the colors, etc. – Mofi Apr 15 '22 at 14:40
  • You can also change the icon. There is most likely somewhere in *MinGW* directory a `*.ico`, `*.bmp`, `*.png` file with a nice *MinGW* related icon. Enter a __Comment__ which is shown as tooltip on hovering the mouse pointer over the shortcut. Then click on button __OK__. Now whenever this shortcut is used, a new Windows command prompt window is opened with __local__ `PATH` containing as first folder path the directory `bin` of *MinGW* and no other process is aware of this directory. That is more or less what IDEs do too. – Mofi Apr 15 '22 at 14:43
  • If you install mingw using msys2 there is a mingw64 terminal in the `C:\msys64` folder provided you installed to the default location. Using gcc/g++ from this terminal will have the compiler properly in the path. When I type gcc --version from the mingw64 terminal on windows I get: `gcc.exe (Rev10, Built by MSYS2 project) 11.2.0 ` – drescherjm Apr 15 '22 at 15:20

1 Answers1

0
SET PATH=C:\MinGW\bin;%PATH%  

set the path via cmd (or manually) before running your commands