"Vscode" under Windows Vscode compiling debug C + +

Source: Internet
Author: User

This article is a super-detailed procedure for Blackkitty documenting the Debug/C + + process using Vscode compilation under Windows

First look at the effect
set breakpoints, variable monitoring, view of call stacks :

use of conditional breakpoints:

Here is the configuration process:

Overall process:

    1. Download and install Vscode
    2. Installing the Cpptools Plugin
    3. Installing the compilation and debugging environment
    4. Modifying the Vscode Debug configuration file
    5. Finished

Download and install Vscode
Https://code.visualstudio.com/Download

Click to download the appropriate version of your favorite, the green version of the extract can be eaten

Installing the Cpptools plugin
Open Vscode, press Ctrl+e to open the Quick Command box, and then wait until you enter the following command

Ext Install Cpptools

Vscode lists the plug-in list after a short network lookup,

Click the button at the arrow to install the plug-in, the installation process may be a bit slow and patient waiting
After the installation is complete, Vscode will prompt you to restart the Vscode, at this time restart

Installing the compilation and debugging environment

Currently debugging under Windows only supports Cygwin and MinGW.
The MinGW is used here.
Here is the installation configuration process for MinGW:
http://mingw.org/
Enter the official dot click on the right Download installer download Installer
Open the installer and click Install to prepare the installation:

Select an installation directory, default to C:\MinGW here is the A:\MinGW
Click Continue to start the installation, the installation process needs to be networked, if the installation prompt error will need to turn over the wall installation
The installation process is quick, and after the Continue button is restored to a usable state, click Finish installation.


Open MinGW Setup Manager for further configuration

Note that GDB must be selected here, otherwise it cannot be debugged

Select several required items right-click make for installation to mark, where GCC and g++ are C and C + + compilers
Select the full section you want to install and click on the upper left installation menu under the Apply Changes application modification, the process needs networking, the middle error can continue, if the final failure will need to turn over the wall to update, proposed to turn over the wall

then configure the system environment variable path, which is a step that must be
Right-click Properties on My Computer:
Then follow the steps below and note that the last item to be created corresponds to the previous MinGW installation location

Modifying the Vscode Debug configuration file
Open Vscode Again, note Configure the System environment variable path and reboot Vscode
Note Vscode debugging needs to be done in an open folder

After opening the folder, create a new test.cpp to enter the code test:

Enter the debug interface to select C + +:

A Launch.json startup configuration file is then generated in the working directory:

Replace the file with the following code:

{"Version":"0.2.0","Configurations": [        {"Name":"C + + Launch (GDB)",//Configuration name, will be displayed in the Boot Configuration drop-down menu            "Type":"cppdbg",//configuration type, only for cppdbg            "Request":"Launch",//Request configuration type, can be launch (boot) or attach (additional)            "Launchoptiontype":"Local",//Debugger Startup type, here only for local            "Targetarchitecture":"x86",//Generate target architecture, typically x86 or x64, can be x86, ARM, ARM64, MIPS, x64, AMD64, x86_64            "program":"${file}.exe",//path of the program that will be debugged            "Midebuggerpath":"A:\\mingw\\bin\\gdb.exe",///Midebugger path, note that this should correspond to the path of the MinGW            "args": ["Blackkitty","1221","# #"],//The command line parameters passed to the program when debugging, usually set to null            "Stopatentry":false,//Set to True when the program is paused at the entrance of the program, and is generally false            "CWD":"${workspaceroot}",//The working directory when debugging the program, usually ${workspaceroot} that is the directory where the code resides            "Externalconsole":true,//Whether the console window is displayed when debugging, generally set to true display console            "Prelaunchtask":"g++"                      //The tasks performed before the debug session started, typically compiler, C + + g++, c gcc}    ]}

Note that the Midebuggerpath will correspond to the path of the MinGW
After replacing save, then switch to Test.cpp, press F5 to debug, this will pop up an information box asks you to configure the task to run the program, click it ~

Here's a casual choice:

Then replace it with the following code:

{"Version":"0.1.0","command":"g++","args": ["-G","${file}","-O","${file}. exe"],//compile command parameters"Problemmatcher": {"owner":"CPP","Filelocation": ["Relative","${workspaceroot}"],"pattern": {"RegExp":^ (. *):(\\d+):(\\d+): \\s+ (Warning|error): \\s+ (. *) $ ","File":1,"line":2,"column":3,"Severity":4,"Message":5}    }}

Save it, then switch to Test.cpp, press F5 again to start debugging ~

Finished!

"Vscode" under Windows Vscode compiling debug C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.