table of Contents
Second, install the C / C ++ plug-ins
Third, configure the debug and compile files
3.1 tasks.json file ---- generated out files
3.2 launch.json file ---- executed out files
First, install vscode
I use the anaconda installation, you can refer vscode home page, there is mounting.
Second, install the C / C ++ plug-ins
Press Ctrl + shift + X, search for C / C ++ and install it. It will install the line.
Third, configure the debug and compile files
3.1 tasks.json file ---- generated out files
In order to facilitate compiling C ++ code VScode, we can similarly g ++ -g main.cpp etc. g ++ command to write VScode mission system.
Press ctrl + shift + p to open the command line, enter Tasks: Run task, Enter! ! ! Will appear the following prompt:
No task to run found. configure tasks...
Then Enter,
Create tasks.json file from template
Then select:
Others Example to run an arbitrary external command.
Create default tasks.json file as follows:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-g", "${file}", "-o", "${fileBasenameNoExtension}.out"]
}
]
}
Here's label name for the task, we will "label" = "echo" was changed to "label" = "build".
Since our instruction is g ++, where the "command" = "echo Hello" was changed to "command" = "g ++" .
Then add g ++ arguments args. If our g ++ instructions: g ++ -g main.cpp, where you can set the parameter as follows:
3.2 launch.json file ---- executed out files
Select the folder / cpp file, press Ctrl + shift + D, click on the left side of the Debug button, select Add Configuration (Add configuration), and then choose C ++ (GDB / LLDB) Enter! ! Launch.json automatically generated file, modifications are as follows:
"program": "enter program name, for example ${workspaceFolder}/a.out",
Changed
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask":"build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
"PreLaunchTask": "build", this parameter must be, otherwise it will error, when debug, saying lauch: file.out file does not exist.
4. Take
F5
Five OPENCV build environment
5.1 configuration opencv
Go here https://github.com/opencv/opencv/releases download, tar.tg file. Pressure.
cd opencv/cmake
cmake ..
suido make
sudo make install
5.2 Configuration vscode environment
5.2.1 c_cpp_properties.json
Press ctrl + shift + p, input edit, select the C / C ++: edit configuration ( json), will pop c_cpp_properties.json. He is the configuration of the external environment.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
修改它
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include", //请确保你的opencv opencv2头文件夹安装在这个目录
5.2.2 task.josn
tasks.json里面修改的是参数问题,我还没试试那个好使
"args": [
"-g",
"${workspaceRoot}/test.cpp",
"-L", "/usr/local/opencv3.4/lib/lib*",
"-o",
"run"
],
"args": [
"-g", "-std=c++11", "${file}", "-o", "${fileBasenameNoExtension}.o",// 设置动态链接库
"-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"
],// 编译命令参数
5.2.3 libjasper.so.1
Lack libjasper.so.1 , so what way, installation chant.
Command is as follows:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev