Use VSCode write c ++ and debugging

Ubuntu system recently changed toss, do not want to engage in visual studio in ubuntu so bulky IDE (of course, that of course can use Visual Studio or the best), I heard VSCode very good use, so try next. VSCode is a lightweight editor, but can achieve very powerful personalization features via plug-in here to try to use VSCode write c ++ code, and debugging.

This aspect of the article written more than enough, just get started their own record some of the problems encountered and reference vscode some blog links.

  1. First on vscode c ++ programming tutorials, reference official tutorial , this tutorial is written in c ++ vscode on WSL (Windows Subsystem for Linux) platform, operating on ubuntu is basically the same.

    Encounter problems:

    1. problem c ++ plug-in installation of
      the mounting vscode and install g ++, and gdb parts are no problem, but when you install c ++ plug-ins follow the prompts vscode seems to have some dependencies is not installed on. Reference this blog solve - practical problems may be due to network or proxy issues, making it impossible to download some dependencies c ++ plug-in, plug-in found in the directory according to the blog said package.jsonfile, and find dependencies URL Download these dependencies (for example, I used uGet download) by other means, and then copy some files to c ++ plugin directory opinions solved in accordance with the blog that way. Open vscode found intellisense make a good, all the same as the official website.
    2. .vscodeSeveral files under the home .jsonfile action
      • task.json-- to set the task / action mode to execute the compilation command, open view its contents, you can see actually executed command g ++ compiler to compile c ++ program
      • launch.json-- debugging settings. task.json when setting compile-related properties, and set attributes associated launch.json runtime, such as can be debugged by running the program gdb
      • c_cpp_properties.json-- intellisense compiler path setting, including a path comprising, c ++ to standard class, the compiler path
  2. Use cmake management projects in vscode in
    by section 1 above, already can write c ++ in VSCode, there are intelligent completion, there are documents, etc., you can also jump to define, view statements, definitions and references and so on, basically on the secondary coding on a like an IDE; but if you want to use in vscode in cmake, open view, compile and debug cmake project management needs how to do?

    - Here reference this blog implementation uses cmake management vscode in. Through this blog we basically know:

    • task.json perform an action, basically the equivalent of vscode command line or script. Using the configuration file to configure the compilation process and the like (for example, to perform the set operation g++using the command gcc compiler to compile the program, or set the operation to invoke build.sha script in build.shthe CMakeLists.txt according to compile CMake), the action is performed usingCtrl+Shift+B

    • launch.json used to set the running configuration, such as which executable file, parameters used to perform execution by the profile can be set to use gdb debugger, start the run / debugCtrl+Shift+D

    • c_cpp_properties.json add headers specified path to the library, etc., add the header file path in order to use auto-completion, such as writing #include <iostcan prompt completion is #include <iostream>; wrote a member-operator .will be the object member variables and functions available such as when

      more than every time a new project or open should be configured task.json, launch.json and c_cpp_properties.json, etc., are too cumbersome. In order not to so much trouble, fool simplified operation, can download and install a plugin CMake Tool, as follows:

      Here Insert Picture Description
      Then appears in the status bar buildbuttons and debugicons (Why do I have here two Buildand Debug, since I accidentally installed two CMake Tool, a 1.3.0, a 1.5.2 =. = ||)
      Here Insert Picture Description
      Click buildto compile your project , if no compiler suite (Kits), you'll be prompted to select packages, as follows:
      Here Insert Picture Description
      after compilation lower right corner may be automatically set up intellisense (such as CMakeListx.txt used in find_package to find an external library to find and add the library contains header file path, cmake tool plug-in will automatically add the path to the read path intellsense to go, so the corresponding auto-complete function can be used);
      Here Insert Picture Description
      then click on the icon to debug debugging, debugging and visual studio in essentially the same F5continue to run, F10stepping, F11jumped, Shift+F11jumped out.

  3. Debugging parameters
    above may have been made by cmake tool to debug a fool, but sometimes a need for a given parameter compiled executable program is running, this time can launch.json file argsgiven parameter back.
    Here Insert Picture Description
    In theory, it should be used when additional parameter to specify the program operations in more than launch.json behind args file, but here I do not know why this change is still not added when debugging parameters on

Published 28 original articles · won praise 14 · views 20000 +

Guess you like

Origin blog.csdn.net/liyunxin_c_language/article/details/104304977