基本流程可以参考
将 VSCode 打造成 OpenCV 的 IDE(C++,window10 1803)
需要修改的地方是:
新版OPENCV库是libopencv_world+版本号
所以需要将
“-lopencv_core345”,
“-lopencv_imgproc345”,
“-lopencv_imgcodecs345”,
“-lopencv_video345”,
“-lopencv_ml345”,
“-lopencv_highgui345”,等全部删除
改为"-l",“libopencv_world455”
没有修改的话会导致找不到库文件
出现错误如下
-file format not recognized; treating as linker script
-1: syntax error
另一个需要注意的地方是tasks.json、launch.json里-o配置程序编译输出文件后缀改为.exe
以下是VSCode中tasks.json、launch.json、c_cpp_properties.json这三个文件的配置
task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++",
"command": "E:\\MinGw\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"E:/OPENCV/opencv/build/x64/mingw/install/include",
"-I",
"E:/OPENCV/opencv/build/x64/mingw/install/include/opencv2",
"-L",
"E:/OPENCV/opencv/build/x64/MinGW/install/x64/mingw/lib",
"-l",
"libopencv_world455"
],
"options": {
"cwd": "E:\\MinGw\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json
"version": "0.2.0",
"configurations": [
{
"name": "gdb build active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "E:\\MinGw\\bin\\gdb.exe",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}",
"E:/OPENCV/opencv/build/x64/mingw/install//include/opencv2",
"E:/OPENCV/opencv/build/x64/mingw/install//include",
"E:/OPENCV/opencv/build/x64/mingw/install/x64/mingw/lib"],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "E:/MinGw/bin/g++.exe",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}