I am programming in C in Visual Studio Code, but I can't compile, as VSC only offers three compilers built in - Node.js, C# Mono, and Extension development. After a little bit of digging I came across the Visual Studio Marketplace. This seemed like the right sort of thing, but only four uncommon languages were there.
I can only assume that C debugging support is built in, I just can't find it or I am going the wrong way about doing it. I attempted to create a new launch.json (the manifest that seems to hold the compiling/debugging settings for each file) and manually entering the GCC binaries that I have, but that didn't end up working. I'm currently stuck manually compiling the C source file I am working on through command prompt.
Would really help if someone could point me in the right direction on what to do.
tl;dr - Help from anyone debugging C in Visual Studio Code
Windows 8, if that matters
Cheers!
Install Visual Studio Code. Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X). Get the latest version of Mingw-w64 via MSYS2, which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries.
GCC stands for GNU Compiler Collection; GDB is the GNU debugger. After configuring VS Code, you will compile and debug a simple C++ program in VS Code. This tutorial does not teach you GCC, GDB, Ubuntu or the C++ language. For those subjects, there are many good resources available on the Web.
A friendly reminder: The following tutorial is for Linux user instead of Windows
If you want to debug your c++ code with GDB
You can read this ( Debugging your code ) article from Visual Studio Code official website.
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
launch.json
fileTo enable debugging, you will need to generate a launch.json
file
follow the launch.json example or google others
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With