1. Installation
The environment is Ubuntu gnome 16.10. It can be installed as follows:
- Install popular IDEs using ubuntu-make. The command is
umake ide visual-studio-code
- Download the deb package from Microsoft's official website and install it by yourself.
2. Configuration
- Install the c/c++ plug-in (Microsoft official plug-in) to support the cpp language .
You can directly search for installation or go to the official website plug-in library to install; you can also enter the command after Ctrl+Pext install c++
- The system needs to install the compilation and debugging environment (gcc, g++). Build-essential can be installed directly under Ubuntu
- Project configuration
Open the project folder with VSCode, open a source file, direct shortcut keys ctrl + shift + D, click the settings icon, select C++ (GDB/LLDB) in the pop-up selection, and the project's launch.json file ( official document ) will be created automatically. ), the default is the debug configuration. But why not run configuration?
- Modify the value of the program field and change it to the executable file path generated by compilation. eg
"program": "${workspaceRoot}/${fileBasenameNoExtension}.out"
. That is, if the source file is case.c, the case.out file will be debugged. - But at this time, the F5 debugging operation will not find the executable file, and the compilation configuration must be done. Add a task option to launch.json:
"preLaunchTask": "build"
. After saving, switch to the source file, press F5 to debug, and a message box will pop up asking to configure the task runner. After selecting, click Others, jump out of the tasks.json ( official document ) configuration file, and configure a task named "build".
{
"version": "0.1.0",
"command": "gcc", // 编译C程序。可以换成 echo 来调试命令参数
"isShellCommand": true,
"tasks": [
{
"taskName": "build", // 任务名
"suppressTaskName": true,
"args": ["-g", "-o", "${fileBasenameNoExtension}.out", "${file}"], // 命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
3. Compile and debug
After saving, switch to the source code and press F5 again to start debugging