Caution
A friendly reminder: The following tutorial is for Linux user instead of Windows
Tutorial
If you want to debug your c++ code with GDB
You can read this ( Debugging your code ) article from Visual Studio Code official website.
Step 1: Compilation
You need to set up task.json for compilation of your cpp file
or simply type in the following command in the command window
g++ -g file.cpp -o file.exe
to generate a debuggable .exe file
Step 2: Set up the launch.json file
To enable debugging, you will need to generate a launch.json file
follow the launch.json example or google others
Step 3: Press (Ctrl+F5) to start compiling
this launch.json file will launch the configuration when you press the shortcut (Ctrl+F5)
Enjoy it!
ps. For those who want to set up tasks.json, you can read this from vscode official (-> TypeScript Hello World)
Caution
A friendly reminder: The following tutorial is for Linux user instead of Windows
Tutorial
If you want to debug your c++ code with GDB
You can read this ( Debugging your code ) article from Visual Studio Code official website.
Step 1: Compilation
You need to set up task.json for compilation of your cpp file
or simply type in the following command in the command window
g++ -g file.cpp -o file.exe
to generate a debuggable .exe file
Step 2: Set up the launch.json file
To enable debugging, you will need to generate a launch.json file
follow the launch.json example or google others
Step 3: Press (Ctrl+F5) to start compiling
this launch.json file will launch the configuration when you press the shortcut (Ctrl+F5)
Enjoy it!
ps. For those who want to set up tasks.json, you can read this from vscode official (-> TypeScript Hello World)
Press Ctrl + Shift + P to pull up the Command Pallette, and Type ext install cpptools. It will install everything you need to debug C and C++.
Debugging in VS code is very complete, but if you just need to compile and run:
https://code.visualstudio.com/docs/languages/cpp
Look in the debugging section, and it will explain everything.
Videos
I already have CodeBlocks (an open source IDE) installed on windows 10. I am practicing basic C programs on it.
Now, I wanted to install VSCode for python, etc. So I installed it and the python extension alongside.
Then I see that it also has support for C/C++ with another extension. It would be nice to use only VSCode for both python and C/C++ so I installed the extension. But it also needs a compiler for C/C++.
I have found some instructions on installing the C/C++ compiler/s here. The process is more complicated than I expected.
Can I somehow use the MinGW compiler that CodeBlocks already has to compile in VSCode?
Should I just stick to non- C/C++ programming with VSCode and keep using CodeBlocks for when I am doing C?
Appreciate any advice.
Edit: SOLVED imgur link
Not sure if this counts, since this is more about running code than writing it.
I have followed the instructions on these sites. I have also made sure to change "Path" in the environmental variables. https://code.visualstudio.com/docs/cpp/config-mingw https://www.mingw-w64.org/
The installation worked, but no matter what I try (running in command prompt, running in Visual Studio) I get something like: "'g++' is not recognized as an internal or external command, operable program or batch file." when I try to execute some code. Why is this?
EDIT 1: Visual Studio Code*, not Visual Studio.
EDIT 2: Seems to be working now! I'm the only user on my computer, but I had to change my system variables - not just the user variables - for it to work.
Hey all,
I'm relatively new to C++ and have installed the basic extensions for it (see the list in the packages sidebar). At first everything worked, but then I had to turn of my computer for a week as I was moving and, when I turned it back on, it could no longer find gcc.
For clarity this is a custom built PC running windows 10 Pro and the newest version of unbutu via WSL.
This bug is preventing me from including anything in the standard namespace, so it's pretty severe. Oddly enough though, gcc does indeed exist at this location and I can use it to compile.
Any suggestions on how to get VSCode to see it again?
VSCode c_cpp_properties.json File exists according to Cygwin WSL recognizes g++ (tested gcc as well; it works too)Hey,,, It will work for you I believe
Blockquote
- First: open the link: https://www.msys2.org/
- Go to the installation and download the installer .. install the exe file.
- search mingw in windows search(windows start)
- there is an app named--> MSYS2 MinGW {64/32}-bit
- run it as administrator
- Found command shell ---> type: pacman -Syu
- Will ask you for some installation click on Y
- Then again go to the same app MSYS2 MinGW {64/32}-bit and run as admin
- and write--> pacman -Ss gcc (in shell that opend after click)
- after clicking there will be bunch of things and now you have to care about your windows arch.. if it is 64 bit then write---> pacman -S mingw-w64-x86_64-gcc (and if its 32 you will find something like that where 64 will replaced by 32 in bunch of commands that are showing in your shell)
- after executing this command gcc will be installed in your system to check write: gcc --version || g++ --version
- After that to install the debugger write pacman -S mingw-w64-x86_64-gdb
- to check write: gdb --version
**Every thing got installed in your system now find the mingW file or mysys2 file on C drive(whereever you r mingW file got saved) go the the minGW 64 || 32 accroding to your operating system there is a bin folder click on that and copy the path inside the bin folder and save it in environment variables path **
Blockquote
Enjoy vs code
Works perfect in Visual Code. You need the following:
- C/C++ extension in Visual Code.
- msys64 installed in C:\
- Add path to msys64 bin folder in environment variable
Instructions:
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
Important the msys64 path doesn't contain spaces so don't install it in Program Files.
You can search "Edit system environment variables" from the windows button, press button Environment Variables, and then add it as a System variable "Path". For me its located in
C:\msys64\mingw64\bin

