12 hours ago C Debugging in Visual Studio: Let's Start with the Basics. Debugging is a crucial part of the development process. In this new series of tried and true C tips, we look at the basics of debugging and step through some more advanced debuggings tips for C. C# for Visual Studio Code (powered by OmniSharp) Welcome to the C# extension for Visual Studio Code! This extension provides the following features inside VS Code: Lightweight development tools for.NET Core. Great C# editing support, including Syntax Highlighting, IntelliSense, Go to Definition, Find All References, etc. The C/C extension adds language support for C/C to Visual Studio Code, including features such as IntelliSense and debugging. In this video I go over adding C/C support to Visual Studio Code and showing how you can have intellisense support for C/C as well as that you can easily.
Since the day that Microsoft released Visual Studio Code, I had installed it on Windows instead of notepad++. Because VS Code does not have a built-in code formatter or beautifier by default, I was eager to see a more powerful VS Code with extensions. Now there it is. We can find many useful extensions on Visual Studio Marketplace. Recently I was writing C/C++ code on Ubuntu and found the extension Clang-Format for beautifying C/C++ code. Let’s take a glimpse of how to make clang-format works with Visual Studio Code on Windows and Linux.
Getting Started with Clang-Format
To install an extension, we can press Ctrl+Shift+P and type in “install extension”. When all extensions listed, search for “format”, and you will see the Clang-Format: After installing the extension, you need to restart VSCode.
To format code, you can call Command Palette again with Ctrl+Shift+P, and then input “format”: The shortcut Ctrl+Shift+I is for Linux. If you want to use it on Windows, you need to use Alter+Shift+F.
If you do not have Clang-Format installed on your system, you will see the prompt:
How to Install Clang-Format on Windows
Download Clang for Windows (32-bit) or Clang for Windows (64-bit).
Install the package and add the path of %LLVM% bin to your system environment.
The shortcut Alter+Shift+F now works in Visual Studio Code for Windows.
How to Install Clang-Format on Ubuntu 14.04
There are two ways to install clang-format on Ubuntu 14.04: the stand-alone clang-format-3.4 or Clang for x86 _64 Ubuntu 14.04. The package size of stand-alone is much smaller than the full LLVM.
If you choose to install clang-format-3.4, the VS Code extension can’t work instantly. It will still prompt you that no clang-format found. Why? The installed clang-format tool is named clang-format-3.4:
To make it work, you just need to create a symlink:
Alternatively, if you download and extract the LLVM package, you will find clang-format under clang+llvm/bin:
Similarly, create a symbolic link for clang-format:
Now, you can format code with Ctrl+Shift+I in Visual Studio Code for Linux.
Gourav Goyal
By the end of this short guide, you’d be able to run, debug, and get IntelliSense for C/C++ files in VSCode. Though, this guide is focused on the Windows platform but can be extended to Mac and Linux with some minor changes.
I extensively used C & C++ in my competitive programmingyears and wanted better support for debugging & IntelliSense. The only options availablewere Dev-C++ (outdated) and the original 'Mammoth'Visual Studio. Lately, I found VSCode and fell in love with it (first love was Atom).I tweaked it around and set it up as a complete IDE For small C, C++ projects especiallygeared towards competitive programming.
Create a sample C/C++ project
- Open/Create an empty folder in VSCode.
- Create a
new.cpp
file inside it like below:
- Install recommended C/C++ extension in VSCode and reload.
Install C/C++ Compiler
C/C++ extension does not include a C++ compiler. So, you will need to install one or use which is already installed on your computer.
Windows: Download MinGW64.zip (latest release) and extract it to the C Drive.
Mac:XCode
Linux:GCC
Also, Make sure to add C++ compiler PATH to environment variable of your platform. For Windows MinGW64 add: C:MinGW64bin
Visual Studio Code For Calculator
Run and Debug C/C++ Code
You’ll notice that there is also a .vscode
folder in your sample project. To configure debug configuration
, 2 files are required launch.json
and tasks.json
inside .vscode
folder.
VSCode can create and auto-configure these files if we try to debug for the first time. To do that, open C++ file in VSCode and either hit F5 or go to Debug -> Start Debugging and select C++ (GDB/LLDB)
then select g++.exe build and debug active file
.
This should create 2 files launch.json
and tasks.json
in .vscode
folder which should look like below (update the MinGW64 path if not correct)
Notice that I’ve added one more optional configuration g++ build & run active file
in launch.json
and g++ build & run
in tasks.json
file for purpose of also Running C/C++ code without debugging. Now you may choose which configuration to pick when you start debugging. You may remove the configuration whichever you won’t need.
Visual Studio Code For C#
launch.json
tasks.json
externalConsole
in launch.json
can be set to true to see code output in cmd instead.
Restart VSCode to take effects of newly added compiler paths.
Open any C/C++ file, set some breakpoints (or not), and hit the Big Green Play Button.
(Shortcut to debug: F5 )
Tip: To hide *.exe
files in the side explorer of VSCode, open settings and paste the below config:
Thanks for reading. Would love to hear your thoughts about it. Connect with me onTwitter andLinkedIn.