I got some problem with using OpenCV on VS Code for C++.
I can compile the C code but when I include the OpenCV libraries, it always displays the following error message:
fatal error: opencv2/opencv.hpp: No such file or directory
My VS Code version is 1.41.1 (user setup).
I downloaded OpenCV 3.4.1 from this site:
https://github.com/huihut/OpenCV-MinGW-Build
The environment path in my computer is:
The path to OpenCV is D://opencv//build.
Here are my configurations for using OpenCV in VS Code:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\bin\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "啟用 gdb 的美化顯示",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.exe",
"-I",
"D:\\opencv\\build\\include",
"-L",
"D:\\opencv\\build\\x64\\mingw\\bin",
"-l",
"libopencv_calib3d341",
"-llibopencv_core341",
"-llibopencv_dnn341",
"-llibopencv_features2d341",
"-llibopencv_flann341",
"-llibopencv_highgui341",
"-llibopencv_imgcodecs341",
"-llibopencv_imgproc341",
"-llibopencv_ml341",
"-llibopencv_objdetect341",
"-llibopencv_photo341",
"-llibopencv_shape341",
"-llibopencv_stitching341",
"-llibopencv_superres341",
"-llibopencv_video341",
"-llibopencv_videoio341",
"-llibopencv_videostab341"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe",
"includePath": [
"${workspaceRoot}",
"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\include",
"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include",
"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++",
"D:\\opencv\\build\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=5",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\include",
"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include",
"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++",
"D:\\opencv\\build\\include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}