21
#include<iostream>
using namespace std;
int main()
{
    cout<<"hi"<<endl;   
    return 0;
}

I am using Sublime text 3, and I am getting this error:

error- 'g++' is not recognized as an internal or external command, operable program or batch file. [Finished in 0.0s]

Garf365
  • 3,619
  • 5
  • 29
  • 41
Rakesh Dagdi
  • 313
  • 1
  • 3
  • 11

7 Answers7

18

Try to set g++ to your system path.

You can refer to this: http://stephencoakley.com/2015/01/21/guide-setting-up-a-simple-c-development-environment-on-windows

msc
  • 33,420
  • 29
  • 119
  • 214
1

I faced the same problem while running the code from command line. And found out that I messed up with MinGW installation. So I reinstalled it,

Do this while installing MinGW ----

  1. After downloading, install MinGW and wait for the “MinGW Installation Manager” to show up.
  2. When the “MinGW Installation Manager” shows up, click on mingw32-gcc-g++ then select “Mark for Installation”
  3. In the menu at the top left corner, click on “Installation > Apply Changes”
  4. Wait and allow to install completely. Ensure you have a stable internet connection during this process.

when it is done, then edit the environment 'Path' Variable as stated in other answer.

In short I followed this

  • After installing visual studio (which is massive) and failing. I tried this and it worked immediaely.... the only issue that i have with this is that the user needs to press `ctrl + alt + n` to run code and not the usual `f5` or `ctrl + f5`.... – D.L Jun 28 '23 at 10:15
0

For me, it's easily fixed by two steps, as below:

  1. Set the environment variable:

    C:/MinGW/bin

  2. Paste the following code in the "launch.json":

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Compiler",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "C:/MinGW/bin",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        },
    ]
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • this gives: `C:\MinGW\bin` does not exist even though the folder is there and i did a copy / paste (to ensure no typo's). – D.L Jun 28 '23 at 10:21
0

Open mingw-w64 folder click on mingw32->i686-w64-mingw32->bin copy this path and set this path in your system environment variables

0

If you keep getting this error, make sure you set up MinGW in Path variable, not separated user\system variables: pic link on imgur here

test
  • 1
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32183540) – robni Jul 11 '22 at 14:40
0

The best thing to do is first of all ensure you have download minGW properly you can refer from this site https://www.msys2.org/ , Be sure to follow all the steps inorder for it to install completely (ps:it takes a while),, after that you can go to environment system variables via settings and a new path C:\msys64\mingw64\bin or wherever your msys64 file might be stored. Hope this helps

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32307583) – Nol4635 Jul 25 '22 at 22:11
-2

Check if you have installed g++ by typing g++ --version. If you already have g++ compiler installed, just hit ctrl + S to save the changes you made, then run the code.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197