The compilation of. JSON file under vscode (1) Linux / G + + (2). The meaning explanation of parameters and predefined variables in JSON


0 Introduction

After turning to Linux / vscode programming, I urgently understand that it is necessary to systematically learn the writing method of relevant configuration files in vscode. The following will be divided into Linux / G + + compiler instructions,. JSON file keyword / replace the meaning of variables, compiler link process principle analysis of several parts to introduce, and opencv as an example, the comprehensive use of the above knowledge.

Introduction of Linux / G + + compiler instructions

Refer to the blog of battlescans, extract the useful part of this article to use, the blog link is as follows, the quality is very high, thank you!!!

(1) For a complete, single. Cpp file, helloworld.cpp The compilation instructions are as follows.

$ g++ helloworld.cpp

Compiler G + + can identify the file as C + + source code file by checking the suffix of the file specified in the command line. The default action of the compiler is to compile the source code file, generate the object file, link the object file and the functions in the C + + library to get the executable program. Then delete the object file. Because the file name of the executable program is not specified in the command line, the compiler adopts the default a.out. The program runs as follows,

$ ./a.out

If you want to specify the file name of the executable program, use the “- O” parameter as follows,

$ g++ -std=c++11 helloworld.cpp -o helloworld

When compiling multiple source files to generate executable programs, you can refer to the above blog content.

(2) The meaning of G + + related parameters

Refer to this post, thank you!

1 G + + – I [path] (capital I, i.e. include path) the compiler searches the header file according to the specified path, and the specified path is the first path to find, eg

g++ -I/usr/include

2 G + + – L [lib] (upper case L) compiler searches for files according to the path specified by – L. generally, after – L, you can use – L to specify multiple library files at one time, eg

g++ -L/usr/lib/x86_64-linux-gnu

3 G + + – L [truncated library name] (lowercase L) compiler to the system default path to find the library file, the library file format is as follows.

The name of G + + – LZ # library file is And the library name is Z

If not, find it in the current directory; if not, find it in the current directoryLD_LIBRARY_PATHIf it still can’t be found, the compiler will prompt that the library can’t be found.

2. The meaning of JSON file parameters

Vscode uses the. JSON ending file as the configuration file, including keywords and related parameters. Take the parameter file in opencv as an example to explain, as follows.


Referring to two posts on the official website of vscode, the link is as follows. #C + + programming environment configuration Launch configurations ා explains in detail launch.json The meaning of parameters in

To be able to debug, you need to generate a launch.json The debugger supported by vscode under Linux is GDB. When configuring, click the configure button and select c + + (GDB / lldb) to create a launch.json File

Among them, preluchtask can launch.json and tasks.json File is used to complete the build task before debugging.

 //Use IntelliSense to understand related properties. 
 //Hover to see a description of an existing property.
 //For more information, please visit:
 "version": "0.2.0",
 "configurations": [
 "Name": "(GDB) launch", // mandatory: it's just a name, but it must be
 "Type": "cppdbg", // force: debugger type, node debugger for node, PHP for PHP, go for go 
 "Request": "launch", // force: launch / attach
 "Program": "${workspacefolder} / ${filebasenamenoextension}. Out" // path of executable file
 "Midebuggerpath": "/ usr / bin / GDB" // debugger location
 "Prelaunchtask": "build" // compile task name before debugging
 "Args": [], // debug parameters
 "stopAtEntry": false,
 "CWD": "${workspacefolder}" // current working directory
 "Environment": [] and // current project environment variables
 "externalConsole": true,
 "Mime": "GDB", // debugger mode / type
 "setupCommands": [
 "description": "Enable pretty-printing for gdb",
 "text": "-enable-pretty-printing",
 "ignoreFailures": true


Refer to the two documents of vscode, and the link is as follows. #Examples in C + + configuration environment #Special introduction tasks.json Of

To build an application from vscode, you have to generate one tasks.json Documents. When generating, we need to specify the compiler as “G + +” and write G + + compiler instructions in args

 // See
 // for the documentation about the tasks.json format
 "version": "2.0.0", 
 "Tasks": [// there can be multiple tasks
 "Label": "build" // compile task name
 "Type": "shell" // the type of compilation task, usually shell / process
 "Command": "G + +" // compile command
 "- G", // this parameter enables the compiler to generate debugging information during compilation
 "${workspace folder} / ${filebasename}" // compiled files, usually. CPP /. C /. CC files, etc
 "- I", // include path instruction
 "- L", // lib path
 "- L", // link library file 1
 "- L", // link library file 2
 "- O", // generates an executable file with the specified name
 "${workspaceFolder}/${fileBasenameNoExtension}.out"           /* -g hello.cpp -I/usr/include -L/usr/lib/x86_64-linux-gnu -lopencv_core -o hello.out */
 "group": {
 "kind": "build",
 "isDefault": true
 "label": "cmakebuild", 
 "type": "shell", 
 "Command": "CD build & & cmake.. / & & make" // the shell compiles the command and does the union operation, that is, if the previous command fails to execute, the latter command will not be executed
 "args": []


(3) Meaning explanation of predefined variables

Thank you for your reference.

${workspacefolder}: indicates the path of the current workspace folder, such as C:: (users, admin, desktop, test)
${workspacerootfoldername}: indicates the folder name of the workspace, such as test
${file}: the absolute path of the file itself, such as C:: (users)  admin  desktop  test  vscode\ launch.json
${relative file}: the path of the file in the workspace, such as. Vscode\ launch.json
${filebasenamenoextension}: the file name of the current file without suffix, such as hello / launch
${filebasename}: the name of the current file, such as hello.cpp/launch . JSON, etc
${filedirname}: the path to the folder where the file is located, i.e. C:: (users / admin / desktop / test). Vscode
${fileextname}: the suffix of the current file, that is. JSON
${linenumber}: the line number of the current file cursor
${ env:PATH }: environment variables in the system


This article about the vscode. JSON file writing (1) Linux / G + + (2). JSON parameters and predefined variables in the meaning of the explanation of the article is introduced here, more relevant vscode. JSON file writing content please search previous articles or continue to browse the following related articles, I hope you can support developer in the future!

Recommended Today

Envoy announced alpha version of native support for windows

Author: sunjay Bhatia Since 2016, porting envoy to the windows platform has been an important part of the projectOne of the goalsToday, we are excited to announce the alpha version of envoy’s windows native support. The contributor community has been working hard to bring the rich features of envoy to windows, which is another step […]