1.下载安装包
2.编译opencv
3.launch.json文件
(左侧带小虫子的按钮)debug--open configuration--c++(GDB/LLDB)
4.task.json文件
快捷键ctrl+shift+p打开命令行,输入Tasks: Run task,会出现如下提示:
No task to run found. configure tasks...
回车,然后依次选择如下:
Create tasks.json file from template
Others Example to run an arbitrary external command.
5.c_cpp_properties.json文件
ctrl+shift+p-->edit configurations(json)-->修改c_cpp_properties,json文件
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file", /* 与launch.json文件里的preLaunchTask的内容保持一致 */
"command": "/usr/bin/g++",
"args": [
"-std=c++11",
"-g",
//"${file}", /* 编译单个文件 */
"${fileDirname}/*.cpp", /* 编译多个文件 */
"-o",
"${fileDirname}/${fileBasenameNoExtension}", /* 输出文件路径 */
/* 项目所需的头文件路径 */
"-I","${workspaceFolder}/",
"-I","/usr/local/include/",
"-I","/usr/local/include/opencv4/",
"-I","/usr/local/include/opencv4/opencv2",
/* 项目所需的库文件路径 */
"-L", "/usr/local/lib",
/* OpenCV的lib库 */
"/usr/local/lib/libopencv_*",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}", //程序文件路径
"args": [], //程序运行需传入的参数
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true, //运行时是否显示控制台窗口
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include/opencv4"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}