VScode Configuration C ++ compiler and debugger environment

  Here logging configuration simple steps C ++ environment for VScode, practice environment for Ubuntu 18.04, VScode 1.27. In Ubuntu environment, the default installation gcc and g ++ compiler, and therefore these steps are already configured default compiler environment, the subsequent step of establishing (For Windows, the user may need to configure itself on the basis of C corresponding to the / C ++ compiler environment, such as a reference  C / C ++ compiler and Debugger  ). 

 

  C ++ provides installation VSCode expand

   As an editor on VSCode nature, providing basic text editing functions. Want to use VSCode be specific language such as C ++ compiler and debugger program, you need to install their corresponding language expansion (Extension), allowing VSCode related with the corresponding language syntax checking, syntax highlighting and other functions. VScode offers a variety of ways to expand into the installation interface, a specific expansion of installation.

  1. Click on the left side of the interface directly correspond to the fifth expansion (Extension) plug-in button or shortcut keys Ctrl + Shift + x to expand into the installation interface;

  

  2. In the search box the keyword "C ++", and select the first expansion of C ++ can be installed (The figure is the author screenshots during the installation of Python);

  

  Way into the expansion mounting interface further comprises a) opened by Ctrl + Shift + p VScode command line, type Extension, drop-down menu Extension: Install Extensions menu can also enter the interface shown in Figure 2; b) the lower left-click interface angle gear button -> Extensions option to enter the interface shown in Figure 2;

  When properly installed C ++ tool to expand the above steps, the reload button on the plug-in or restart VScode the plug into force, VSCode to support basic C ++ related features.

  (VSCode expansion also provided, including theme format, all kinds of tools, users can explore on their own and use)

 

  VSCode Open Directory

  C ++ makes VSCode expand installation has the basic syntax highlighting and checking. To VSCode can compile and debug the program, also needs to be configured to compile and test environments.

  There are two ways to use VSCode way to open the folder:

  1) into the command line directory source, said source to open the folder VSCode command "code.";

  2) In VSCode graphical interface, directly through the File -> Open Folder Options, select the file directory corresponding navigation and open;

  Both ways are open directories will be treated as a new work area (workplace), and create a hidden directory in the directory .vscode to record vscode related settings corresponding to the case. When configuring a C ++ environment, associated with compiling and debugging C ++ program that is located above .vscode configuration file directory, in the form of json file. The following three important json profiles are introduced.

  

  VSCode carried C ++ compiler and debugger related

  c_cpp_properties.json

  This file is used to specify a general compiler environment, including the header file path, the compiler, and the like. By Ctrl + Shift + pd open a command line, type the keyword "C ++", select "C / C ++ Edit configuration" in the drop-down menu, the system will automatically create a file in the .vscode c_cpp_properties.json directory for users to compile areas configuration environment. The default profile shown as follows.

{
     " The Configurations " : [ 
        { 
            " name " : " Linux " ,               // Environmental name
             " includePath " : [
                 " $ {workspaceFolder} / **"    // specify the header file path specified here is the current working directory, if need to add later 
            ], 
            " the Defines " : [],
             " compilerPath " : " / usr / bin / G ++ " ,    the path // compiler can be set according to their installation
             " cStandard " :"c11" ,
             " CppStandard " : " C ++. 17 " ,        // set the C / C ++ standard used
             " intelliSenseMode " : " Clang-x64- " 
        } 
    ], 
    " Version " : . 4 
}

  Value of the bond is typically the configuration file has been generated by default, if subject to change during development, directly modify the above values.

 

  build.json

  This file is used to specify the rule to compile a program, that is, how the source file is compiled into an executable program. Open by Ctrl + Shift + p command line, type the keyword "task", and select Tasks in the drop-down menu: Configure Default Build Task -> Create tassk.json file from template -> Others, the system will automatically .vscode directory Creating build.json file, compiled for the user to set specific rules.

  Note that at this time only generate a simplified template of a task.json, modify the value of the label inside the key, then select the above Tasks: Configure Default Build Task Options, select the label name after modifications, the task.json file will change, and compiled object set as the default, which is generally the format shown below. Wherein a user key needs to be modified according to the actual situation.

{
   " Version " : " 2.0.0 " ,
   " Tasks " : [ 
    { 
      " label " : " Build the Hello world " ,        // current compilation task name 
      " of the type " : " shell " ,
       " the Command " : " G ++ " ,                    // execution of compile-time 
      " args " : [ " -g ", "-o" , " HelloWorld " , " to helloworld.cpp " ],     // passed to the command parameters of the 
      " Group " : {
         " kind " : " Build " ,
         " The isDefault " : to true                  // to True, a user can Ctrl + Shift + B run directly compilations 
      } 
    } 
  ] 
}

  The above file, specify the compile and run the program through the command options, args option given by the arguments passed to the compiler when isDefault True (the default), the user uses Ctrl + Shift + b compilation process can be run directly, or You can also open by Ctrl + Shift + p command line, select Tasks: run Build Task run the above compilation process.

 

  launch.json

  The document is mainly related to the program being debugged. Users can open a command line by Ctrl + Shift + p, type the keyword "launch", select "Debug: Open launch.json" -> "C ++ (GDB / LLDB)", you can open the configuration file launch.json debugging. In VSCode user press F5 to enter debug mode, i.e. above launch.json file contents and provided the basic requirements when debugging. As shown in the following basic options launch.json file.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/helloworld",        //The full path of the executable file, the file name build.json consistent 
            " args " : [],
             " stopAtEntry " : to false ,            // if tentatively executed in the main function of the 
            " CWD " : " $ workspaceFolder {} " ,
             " Environment " : [],
             " externalConsole " : to true ,         // run in the newly opened terminal rather than VSCode in 
            " MIMode " : " gdb " ,
             "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

  After the above-mentioned documents configured, the user can enter debug mode F5.

 

  reference

  C/C++ for VScode

  Use VSCode compilation and debugging under Linux:  the Using the Mingw-W64 in VS Code

  Configuring C/C++ debugging 

  Debugging in Visual Studio Code

  VScode operations:  basic use of Visual Studio Code

 

 

   VScode configure Python environment

  VScode arranged Python environment and C ++ environment similar steps. You first need to install the appropriate expanded to VSCode, supra installation VSCode expand section.

  Thereafter, in order to run smoothly Python program, the user needs to select the appropriate Python interpreter (the Python system requires the interpreter has been installed). The user can open by Ctrl + Shift + p command line, and enter the command Python: Select Interpreter, information of the system will be listed interpreter installed, the user can be selected as necessary.

   

  Note that the above is provided according to the Python interpreter environment effects of different settings are different. If the user does not open the project folder in VScode at the time of setting the Python interpreter, at this time is the selected Python interpreter is set to the global default interpreter that subsequent use VScode open Python project will use the default interpreter . If the user select the specific explanation in the working directory, that is used to select the subsequent working directory runtime interpreter.

  reference

  Python in Visual Studio Code  

Guess you like

Origin www.cnblogs.com/yhjoker/p/9831671.html
Recommended