准备工作
安装VScode
安装 远程 ssh-remote
Linux环境准备
gcc -v
gdb -v
库函数
命令: gcc -v -E -x c++ -
C++ extension
安装 VScode插件 C++ extension for VS Code.
配置环境写代码
01.Build helloworld.cpp
代码
02 Running the build and Modifying tasks.json
create a tasks.json file to tell VS Code how to build (compile) the program
Terminal > Configure Default Build Task > Choose C/C++: g++ build active file
03.Debug helloworld.cpp
create a launch.json file
Run > Add Configuration... and then choose C++ (GDB/LLDB). Choose g++ build and debug active file.
04.more C/C++ configurations
create a c_cpp_properties.json file
冲突和问题解决
头文件包含问题
Cmake “.cmaketools.json”文件内容去覆盖 “c_cpp_properties.json”
要求
使vscode 能够支持对于opencv的库导入和语法提示、
使gcc 支持对含有opencv源代码的编译、
使gdb 支持对含有opencv代码的可执行程序的调试。
解决办法:
opencv的库导入和语法提示,
可直接通过修改.vscode配置文件中c_cpp_properties.json实现
gcc对含有opencv源代码的编译,
需修改task.json中编译命令行中加入相关头文件目录、链接库目录以及相关的链接库文件,
而这本身opencv并不自带,
需要自行通过利用cmake编译opencv源文件生成,而Cmake的编译又需要python的环境
gdb对含opencv相关代码的可执行调试,
需要gdb加载支持可执行文件中opencv相关功能的dll,
这依然是通过利用cmake编译opencv源文件代码生成的
具体配置文件
含c++的文件夹,将会生成一个.vscode文件夹,所有的配置将在这个文件夹中进行配置
01.task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"`pkg-config", "--cflags", "--libs", "opencv`",
"-I", "/usr/local/include",
"-I", "/usr/local/include/opencv",
"-I", "/usr/local/include/opencv2",
"-L", "/usr/local/lib",
"-l", "opencv_core",
"-l", "opencv_imgproc",
"-l", "opencv_imgcodecs",
"-l", "opencv_video",
"-l", "opencv_ml",
"-l", "opencv_highgui",
"-l", "opencv_objdetect",
"-l", "opencv_flann",
"-l", "opencv_imgcodecs",
"-l", "opencv_photo",
"-l", "opencv_videoio"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
02 launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["/data/video/video/test.mp4","/data/video/frame/"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"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"
}
]
}
03.c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/c++/5",
"/usr/include/x86_64-linux-gnu/c++/5",
"/usr/include/c++/5/backward",
"/usr/lib/gcc/x86_64-linux-gnu/5/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
"/usr/include",
"/usr/include/opencv2",
"/usr/include/opencv",
"/usr/lib/x86_64-linux-gnu/"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++98",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
参考:
Using C++ on Linux in VS Code https://code.visualstudio.com/docs/cpp/config-linux
小白也能懂的ubuntu下Vscode中使用C++运行opencv https://www.jianshu.com/p/41f87292b34c
opencv3.2.0实现视频抽帧,并保存成图片 https://www.cnblogs.com/ilykaihui/p/8010566.html