Can't compile code "launch: program <program_path> does not exist " - c++

I have simple console application in C++ that I succeed to compile with Visual Studio.
I wanted to try Visual Studio Code so I copied the directory to the computer with Visual Studio Code installed.
I installed the C++ extension:
I put break point at the beginning and press F5 and I received an error:
launch: program 'enter program name, for example
c:\Users\student1\Desktop\ConsoleApp\a.exe' does not exist.
Of course the the program does not exist, I am compiling it in order for the code to become the program.
I followed the instruction and I went to the launch.json file:
I changed the "program" value to: "${workspaceRoot}/a.exe" instead of "enter program name, for example ${workspaceRoot}/a.exe".
But the same problem still exist.
Any idea ?

Spent 2 hours on this.
Ideally, VS Code shouldn't make so difficult for beginners
VS Code can give prompts for each installation, etc. automatically, in a step by step manner, like Idea editors, so that it wont be so long procedure for beginners.
Sequence of steps to do (most of the things are one time):
one time:
install a C/C++ complier, add to PATH environment variable
install C/C++ plugin for visual studio code
tell visual studio code where the compiler is and what is the short cut to build and run
these are files under ".vscode" (see below)
every project:
crate a project
build project
run project
Detailed:
One time:
Note: Point 'A' below can be skipped if you already have a compiler.
A. Install a compiler (if you don't have one already)
Example below, installs MinGW c++ compiler on Windows:
Download from here: https://sourceforge.net/p/mingw-w64/mailman/message/36103143/
1. For windows, I downloaded https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v5.0.3.zip
2. unzip mingw-w64-v5.0.3.zip
3. rename unzipped folder to MinGW, Move it to C:\MinGW\
4. verify that you have "C:\MinGW\bin\gcc.exe" director/file, otherwise make necessary change to folder
B. Add your compiler to PATH environment variable
1. Add "C:\MinGW\bin" to PATH > user environment variable
2. verify gcc command works from cmd
restart your cmd
run below command in 'cmd'
where gcc
The output should be: C:\MinGW\bin\gcc.exe
C. Restart your visual studio code
1. install C/C++ plugin, as below:
From Menu
View > Extension
Search & Install below extension
C/C++
Every project:
Note: You can copy paste the .vscode folder every time
A. Create a below "myproj" folder & files, like below in below structure:
C:\myproj\myfile.cpp
C:\myproj\.vscode\
C:\myproj\.vscode\c_cpp_properties.json
C:\myproj\.vscode\launch.json
C:\myproj\.vscode\settings.json
C:\myproj\.vscode\tasks.json
B. Download & overwrite the above ((5 files)), from below link
https://github.com/manoharreddyporeddy/my-programming-language-notes/tree/master/vscode-c%2B%2B
C. Restart your visual studio/vs code
D. Open project in vs code & run project:
Drag and drop "myproj" folder into visual studio code
BUILD PROJECT: press "Ctrl + Shift + B" to build your myfile.exe
RUN PROJECT: press "Ctrl + F5" to run your myfile.exe
Thats all, hope that helped.
More info: https://code.visualstudio.com/docs/languages/cpp
Optional
To format C++ better
C++ formatting
1. Install Clang:
Download from: http://releases.llvm.org/download.html#5.0.2
I have downloaded for windows
"Pre-Built Binaries:" > Clang for Windows (64-bit) (LLVM-6.0.0-win64.exe)
2. Select Add to PATH while installing.
3. Install vs code plugin "Clang-Format" by xaver, this wraps above exe.
4. Restart visual studio code.
Note:
Issue: As of June 2018, Clang does not format the newer C++17 syntax correctly.
Solution: If so, move that code to another file/ comment & restart the vs code.
That's all. Now press Alt+Shift+F to format (similar key combination in other OS)

The error ".exe file does not exist" in vscode can occur because of the following reasons:
If the file name contains white spaces
If there is re-declaration of variables or other kind of compilation errors

This problem is mainly due file name , as per below table the name of the binary will be audioMatrixBin in windows folder not audioMatrixBin.exe, but we have to mention filename.exe here.
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "audioMatrixBin.exe",
"args": ["AudioMxrMgr4Subaru.conf"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true
}
]
}

Go to launch.json(we've encounter problem with .json file that's why we're here)
Change 'cwd' & 'miDebuggerPath' where your 'gdb' is(mine is default).
"cwd": "C:\\MinGw\\bin",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
(you can copy-paste if yours is default too).
Now run with 'gcc.exe-Build and debug active file'
(run your file with this option, this should run)

Make sure your "program" and "cwd" properties are actually correct. Check the path it tells you and compare with the path you want them to be.

BUILD your PROJECT .exe file : press "Ctrl + Shift + B" to build your example.exe

It seems that launch.json file needs to have the correct configs.
please check the configurations as per the below link, if you are using VS build tools
https://code.visualstudio.com/docs/cpp/config-msvc
or delete the launch.json file, gotoRun > Add Configuration... and then choose C++ (Windows), Choose cl.exe build and debug active file. Check the new name in launch.json and try again.

This video explain it very well how to setup vscode for c, I did it on Ubuntu.
https://www.youtube.com/watch?v=9pjBseGfEPU
Then I use this reference to setup c++,
https://code.visualstudio.com/docs/cpp/config-linux
I just had to replace "command": "/usr/bin/gcc" with
"command": "/usr/bin/g++",
from the example on the video.
and you can update the label on both tasks and launch if you want it.
this is how my c++ setup ended up.
tasks.json for c++
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
// "command": for classic c, "command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/bin/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"isDefault": true,
"kind": "build"
}
}
]
}
launch.json for c++{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/bin/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file"
}
]
}

In your launch.json file check the "miDebuggerPath" and see if the same path is defined in your environment variables.

To resolve this proble one has to make sure three things are in order:
You have successfully downloaded and install the gcc (compiler) and gdb (debugger). To check this you should be able to type
gcc --version
and
gdb --version
and get the correct results
Once done with this step compile the myfile.c using this command.Make sure that your file has a main() function ,otherwise the produced myfile.exe will not be recognised by the debugger.
gcc -c myfile.c -o myfile.exe
Add a launch configuration using gcc.
In the launch configuration
manually add the path to the executable "program": "${workspaceFolder}/myfile.exe"
In the launch configuration
manually add the path to the debugger "miDebuggerPath": "C:/MinGW/bin/gdb.exe"

Nuke everything and use the build active file tasks:
Delete all files within the .vscode folder.
Select Terminal > Configure Tasks
Select appropriate system task (i.e. for Mac, C/C++: clang build active file).
Open .vscode/tasks.json
Configure C++ language standard by specifying the std flag (i.e. "-std=c++17") at the top of the args array.

the problem for me was an error during the run time that the compiler didn't notice before. then the .exe file didn't built, therefore the .exe file does not exist so you have to check if your script is fine even if no error is found by the debugger.

{In launch.json file where name : (Gdb) launch ,
step 1: enter the complete address of program for eg, c:/users/.....xyz.exe.
step 2: In Mi-debugger path complete address of bin in mingw folder which contains the Gdb debugger so the address would be c:/mingw/....gdb.exe repeat step 2 for the first configuration in launch.JSON
step 3 IN CWD , copy the same path but only till /bin
That should work }

Related

Error during build of cpp file in VSC: "Errors exist after running preLaunchTask 'C/C++:cpp.exe build active file"

I am unable to run my code and execute the build of the .exe file in the cpp language in Visual Studio Code.
I have downloaded and installed GCC, MinGW software, MinGW-w64 GCC, etc. according to the instructions here and have successfully verified that gcc g++ and gdb are all installed (by checking 'gcc --version' etc in the commad prompt). My intent is to use this compiler to compile my code but it seems I cannot find the correct compiler under the options listed here to simply 'build and debug the active file'.
I also (and perhaps consequentially) have run into a problem with launch.json not being able to build the executable file.
Can someone please help me with this? This is incredibly frustrating and I simply want to be able to run my code. I downloaded MinGW along with gcc is a good compiler for this very purpose.
Image of error message 1: here, to which I click 'debug anyway' and get the next error:
Image of error message 2: here.
Image of launch.json with the configuration that I thought would be appropriate (I found this from another source online): here.
Thank you!!
I recommend deleting all the configurations under the .vscode directory, as they can be regenerated again. After deletion, follow the steps:
Go to your program file, and press F5 to launch debug.
Select g++.exe build and debug active file or a convenient option.
A tasks.json under the .vscode will be generated with the appropriate instructions and the program will be executed instantly.
For example, in my case, it was this:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\TDM-GCC-64\\bin\\g++.exe",
"args": [ // ----- given by me in C/C++ extension settings
"-fdiagnostics-color=always",
"-Wall",
"-O3",
"-pedantic",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

The configuration option popup for debugging a c++ project in Visual Studio Code does not appear

so I want to debug my .cpp program file but when I click on the Run and Debug button and proceed to select my debugging environment (C++ (GDB/LLDB)), the popup to select the configuration option does not even appear at all and the debugging just doesn't start.
This is before I click the environment popup:
and this is after:
Any help I can get for this problem is greatly appreciated as I can't seem to find any solutions at all on the internet, thank you very much!
p.s I've already tried uninstalling VS Code completely off my laptop and resetted all the settings and it didn't work.
Are you sure you installed the C/C++ Studio Code extension? If you don't get the popup, try writing the json files manually.
Create a .vscode folder in your working directory. In there create a file launch.json in which you declare how you run the debugger
{
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}\\test.exe",
"stopAtEntry": true,
"cwd": "${workspaceRoot}",
"preLaunchTask": "Build Debug",
"miDebuggerPath": "c:\\mingw64\\bin\\gdb.exe"
}
]
}
This runs the gdb debugger that came with MinGW. You need to provide the path to your debugger at miDebuggerPath.
This debugs an executable test.exe that needs to be created in debug mode. For this you have the preLaunchTask option. In .vscode create a file tasks.json in which you describe the debug task as
{
"tasks": [
{
"type": "cppbuild",
"label": "Build Debug",
"command": "g++",
"args": [
"${workspaceRoot}\\test.cpp",
"-g",
"-o",
"${workspaceRoot}\\test.exe"
],
}
],
"version": "2.0.0"
}
This uses the gcc or g++ compiler that also comes with MinGW to compile a single source file test.cpp into the test.exe binary. You can select the debug launch configuration in the lower left corner of Studio Code and click Run.

VSCode+LLDB debugging not working properly in Vagrant-Ubuntu

I am using Vagrant to launch a VM of Ubuntu and compile my C++ code in Linux. The Linux version is 5.8.0-59-generic.
The makefile build command is exec: main.o other_lib.o ${CXX} ${CXX_FLAGS} -lc++abi bin/main.o bin/other_lib.o -o bin/exec -g -fstandalone-debug. After running make exec and ./bin/exec, the program can successfully run. However the debugging part is bugged. This is the launch.json config for LLDB:
{
"name": "debug exec lldb",
"type": "cppdbg",
"request": "launch",
"program": "/home/vagrant/bin/exec",
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"miDebuggerPath": "/usr/bin/lldb-mi",
"preLaunchTask": "debug exec",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "settings set target.run-args ${input:lldb-debugger-args}"
}
]
}
The first time I ran this debugging config using F5, vscode prompted miDebuggerPath invalid. I found that there was no /usr/bin/lldb-mi executable file in the system, so I ran sudo apt-get install lldb. This is where things get weird:
I tried to run the debugging process via VSCode, and there is no miDebuggerPath invalid error. However, after hitting F5, the terminal will output [1] + Done(127) "/usr/bin/lldb-mi" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-ly4ql3cx.s1b" 1>"/tmp/Microsoft-MIEngine-Out-gfkz1mbe.fex" and print a new prompt that listens for the next command. The hovering debug toolbar of VSCode appeared, but there is a constantly running progress bar (see below). The whole debug process is stuck.
Using ls in /usr/bin/, the lldb-mi file appears red. Using ls -l /usr/bin/lldb-mi indicates that it is a broken link, pointing to another broken link lldb-mi-11:
/usr/bin/lldb is an existing executable. However lldb-mi seems to be a "machine interface" of lldb, and I'm not sure if using lldb as the miDebugger can work.
How can I fix this problem (finding a substitution of lldb-mi or somehow fixing the broken link problem of lldb-mi)?
lldb-mi used to be a part of the lldb project, but it languished for quite a while without a maintainer, and eventually it was broken out into a separate package on GitHub in the hopes that as a stand-alone thing it would get more support from the people who used it. There might be an apt-get for it as a standalone package? Not sure about that. But it's still available on GitHub, so if all else fails you can get and build it yourself. The source code is here: https://github.com/lldb-tools/lldb-mi, which has a README on how to build it.
But if you are primarily interested in using VSCode, you might try lldb-vscode instead. Rather than using the MI interface (which is pretty long in the tooth at this point), it uses MicroSoft's own debugging protocol, and is currently in active development. The lldb-vscode binary does get built as part of the regular lldb build.

How to compile and run a c++ source file in visual studio code

I've searched for an answer to this question, but couldn't seem to find one. I know that we can use task.json files to automate the build process. But I want to use Visual Studio Code to implement algorithms in C++ for competitive programming. I want to be able to compile a program, and run it all in one go, if there aren't any errors. If there are errors, I would like them to be displayed.
Also, visual studio code comes with an integrated terminal, so it would be nice if the program output could be redirected there.
Also, how can we map a keyboard shortcut to run this task.
I'm using Visual Studio Code 2019 on Windows 10 with the MinGW G++ compiler.
EDIT
I've tried Escape0707's answer below, and I tried executing 'Run Code' with the default key binding of Ctrl + Alt + N but I'm getting this error.
Updated method which combines make and vscode-cpptools debug:
If you don't care about VSCode integrated debugging tools, which will give you the ability to set breakpoints, change variable value during runtime, inspect variable value, and etc, and you want a somewhat easier, simpler, faster, transparent way to invoke the good old command line tools, skip this section and checkout Code Runner below.
The default configurations come with VSCode C++ extension are kind of slow for low-end machines. The worst part is that they will always rebuild your executable, and don't support 'Start Without Debugging'. Below is a workaround for Linux (and of course remote-WSL).
To address the first issue, you setup make (for simple one source file compiling you only need to install make) to build your source codes, and setup the build task in tasks.json. To address the second issue, you create another task just to run the built executable after the first task finished:
Use Intellisense to learn about each properties in configs.
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"presentation": {
"clear": true,
"focus": true,
"panel": "shared"
},
"tasks": [
{
"label": "make active file",
"type": "shell",
"command": "make",
"args": ["${fileBasenameNoExtension}.out"],
"problemMatcher": "$gcc",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "run active file executable without debuging",
"type": "shell",
"command": "${fileDirname}/${fileBasenameNoExtension}.out",
"presentation": {
"clear": false
}
},
{
"label": "make and run active file without debuging",
"group": {
"kind": "test",
"isDefault": true
},
"dependsOn": [
"make active file",
"run active file executable without debuging"
],
"dependsOrder": "sequence"
}
]
}
To enable debugging using VSCode in this way, first make sure you added -g compile flag to CXXFLAGS in Makefile.
For quick information about how to write a Makefile, see this, or this, or this. Or check this last part of this answer.
Then, create the following launch.json:
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "make and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"cwd": "${workspaceFolder}",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
Now you can use command palette to try Task: Run Build Task, Task: Run Test Task, Debug: Start Debugging.
Original answer
Please consider Code Runner, as it seems faster (for me) than VSCode's built-in debug procedure for practicing with many small C++ code files. I'll describe how I use that extension to satisfy a similar requirement.
Make sure you've configured your PATH to include clang++ so you can invoke it from the integrated terminal.
You can also use g++ by substitute clang++ below with g++. I prefer clang++ as it provides stricter checks for C++ beginners like me.
Install the extension.
In your VSCode's settings.json, consider adding the following entries:
"code-runner.clearPreviousOutput": true,
"code-runner.preserveFocus": false,
"code-runner.runInTerminal": true,
"code-runner.saveFileBeforeRun": true
And add the last customization code-runner.executorMap to user/workspace setting that describes which command you would like the extension to send to the terminal when current filename's extension meets the specified ones. For example:
"code-runner.executorMap": {
"cpp": "\b\b\b\b\b\b\b\b\b\bclang++ -std=c++17 $fileName -o a.out && ./a.out"
},
The above setting tells the extension, "When see a .cpp file, send 10 Backspace to terminal (to delete any mistyped characters) and call clang++ -std=c++17 *filename* -o a.out && ./a.out.
I use this command on my Linux machine, for Windows, try change the filename extension of the output file to .exe and invoke it with .\a.exe or simply a.exe.
Finally, map the Run Code command to your preferred keybinding in VSCode's Keyboard Shortcuts settings. Mine is to bind it to F5 which is originally bound to Debug: Continue.
Happy coding!
Update about make
Read on to learn how to avoid redundant compiling process and speed up case test by utilizing GNU make. I'll do this on Linux and only for C++, since I have not used make on Windows or OS X and C++ is the best for ACM.
Make sure make is installed and in your PATH
Create a file named Makefile (or makefile) under the same directory you invoke make. (Or in another directory and make -f /path/to/Makefile).
Redefine compiler options to whatever you like in the Makefile, e.g.:
CXX = clang++
CXXFLAGS = -std=c++17 -g -Weverything -Werror
Create auto-target rule for *.out in the Makefile, i.e.:
%.out: %.cpp
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $#
Attention: must use Tab to indent the second line, not Spaces.
Change code-runner.executorMap to :
"code-runner.executorMap": {
"cpp": "\b\b\b\b\b\b\b\b\b\bmake $fileNameWithoutExt.out && ./$fileNameWithoutExt.out"
(Optional) To ignore *.out for git:
echo "*.out" >> .gitignore
(Optional) To remove *.out in current directory:
rm *.out
Now the Run Code command will invoke make and make will only regenerate .out file when the corresponding .cpp file is newer than the .out file, thus allows us to skip compilation and proceed with testing even smoother.
The CXXFLAGS is for C++ compiler options, CFLAGS is for C compiler options. You can find other language compiler options and their variable name using make -p, Google and GNU make manual#Automatic-Variables.
To Build/run C++ projects in VS code , you manually need to configure tasks.json file which is in .vscode folder in workspace folder . To open tasks.json , press ctrl + shift + P , and type Configure tasks , and press enter, it will take you to tasks.json
Here i am providing my tasks.json file with some comments to make the file more understandable , It can be used as a reference for configuring tasks.json , i hope it will be useful
After configuring tasks.json , to compile and run your c++ file , press ctrl+shift+B , this is shortcut for running build tools in vscode . Your C++ program will now run on vscode integrated terminal only .
If this presents some issues , then change default terminal to cmd(by default it is powershell in windows) and make sure there aren't any spaces in path to your file .
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build & run", //It's name of the task , you can have several tasks
"type": "shell", //type can be either 'shell' or 'process' , more details will be given below
"command": "g++",
"args": [
"-g", //gnu debugging flag , only necessary if you want to perform debugging on file
"${file}", //${file} gives full path of the file
"-o",
"${workspaceFolder}\\${fileBasenameNoExtension}", //output file name
"&&", //to join building and running of the file
"${workspaceFolder}\\${fileBasenameNoExtension}"
],
"group": {
"kind": "build", //defines to which group the task belongs
"isDefault": true
},
"presentation": {
"echo": false,
"reveal": "always",
"focus": true,
"panel": "shared",
"clear": false,
"showReuseMessage": false
},
"problemMatcher": "$gcc"
},
]
}
All the properties in the presentation of tasks.json are just used to customize build tasks as per your needs , feel free to change them to what you like best . You can read about presentation properties (and other things) on vscode tasks documentations

'g++' is not recognized as an internal or external command, operable program or batch file

#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]
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
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 ----
After downloading, install MinGW and wait for the “MinGW Installation Manager” to show up.
When the “MinGW Installation Manager” shows up, click on mingw32-gcc-g++ then select “Mark for Installation”
In the menu at the top left corner, click on “Installation > Apply Changes”
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
For me, it's easily fixed by two steps, as below:
Set the environment variable:
C:/MinGW/bin
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
},
]
}
Open mingw-w64 folder
click on mingw32->i686-w64-mingw32->bin
copy this path and set this path in your system environment variables
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
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
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.