How to configure Visual Studio Code Compiler / Debugger in GCC?

I program in C in Visual Studio code, but I cannot compile it, because VSC offers only three built-in compilers - Node.js, C # Mono and Extension. After a little digging, I came across the Visual Studio Marketplace . This seemed correct, but there were only four unusual languages.

I can only assume that C debugging support is built-in, I just can't find it, or I'm wrong about that. I tried to create a new launch.json file (a manifest that appears to contain compilation / debugging options for each file) and manually enter the GCC binaries that I have, but that did not finish the job. I am currently stuck manually by compiling the C source file that I am working on the command line.

It would really help if someone could point me in the right direction what to do.

tl; dr - help from any C debugging in Visual Studio code

Windows 8 if it matters

Hooray!

+32
c gcc visual-studio visual-studio-code
source share
7 answers

Ctrl + P and enter "ext install cpptools", it will install everything necessary for debugging 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 explain everything.

+15
source share

precaution

Friendly Reminder: The following guide is for Linux users instead of Windows.

Guide

If you want to debug your c ++ code with GDB

You can read this article ( Debugging your code ) from the official Visual Studio Code website.

Step 1: Compiling

You need to configure task.json to compile your cpp file

or just type the following command in the command window

 g++ -g file.cpp -o file.exe 

create debug .exe

Step 2. Configuring the launch.json file

To enable debugging, you need to generate launch.json file

follow the example of launch.json or google others

Step 3: Press ( Ctrl + F5 ) to start compilation

this launch.json file launches the configuration when you click on the shortcut ( Ctrl + F5 )

Enjoy it!

ps For those who want to configure tasks.json , you can read this in the official vscode (-> TypeScript Hello World )

+10
source share

There is a much simpler way to compile and run C code using GCC without the need for customization:

  1. Install Code Runner Extension
  2. Open the C code file in a text editor, then press Ctrl+Alt+N or press F1 and then select / enter " Run Code or right-click the text editor and select" Run Code in the context menu, the code will be compiled and run, and the output will be shown in the output window.

Moreover, you can update the configuration in the settings.json file using various C compilers, by default you can configure the C configuration as follows:

 "code-runner.executorMap": { "c": "gcc $fullFileName && ./a.out" } 
+8
source share

I just wanted to add that if you want to debug material, you must compile it with debug information before debugging, otherwise the debugger will not work. So in g ++ you need to do g++ -g source.cpp . The -g flag means that the compiler will embed debugging information in your executable so that you can run gdb on it.

+4
source share

For Windows:

  1. Install MinGW or Dev C ++
  2. Open environment variables
  3. In the system variable, select Path → Edit → Create
  4. Copy this C:\Program Files (x86)\Dev-Cpp\MinGW64\bin to a new window. (If you have MinGW installed, copy its / bin path).
  5. To check if you have successfully added it: Open CMD -> Enter "gcc" and it should return: gcc: fatal error: no input files compilation terminated.
  6. Install C / C ++ for Visual Studio Code && C / C ++ Compile || Code runner
  7. If you only installed the C / C ++ Compile Run extension, you can compile your program using F6 / F7
  8. If you installed the second extension, you can compile your program using the button in the top panel.

Screenshot: Hello World compiled into VS Code

0
source share

EDIT: Since March 2016, Microsoft has been offering the C / C ++ extension for Visual Studio code, and so the answer I originally gave is no longer valid.

Visual Studio Code does not support C / C ++ very well. As such, it does not support the natural support for gcc or gdb in Visual Studio Code. Most of all it will be syntax highlighting, advanced functions such as> intellisense are not supported by C. You can still compile and debug the code> that you wrote in VSC, but you need to do this outside of the program itself.

-one
source share

You need to install the C compiler, the C / C ++ extension, configure launch.json and tasks.json to be able to debug C code.

This article will help you how to do this: https://medium.com/@jerrygoyal/run-debug-intellisense-cc-in-vscode-within-5-minutes-3ed956e059d6

-one
source share

All Articles