只记录关键和容易出错部分:
1.下载完所需要的Opencv、Vscode、CMake并配置好环境变量
2.关键点 CMake-gui时,需要把CMakeDownloadLog里的确实的下载都下载好放到指定路径下并重新configure \ generate \ minGW32-cmake -j 8 \ install
3.最主要还是vscode的json的配置,如下
c_cpp_properties.json
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"E:/Cpp/C++/opencv/build/x64/mingw/install/include",
"E:/Cpp/C++/opencv/build/x64/mingw/install/include/opencv2",
"E:/Cpp/C++/opencv/build/include",
"E:/Cpp/C++/opencv/build/include/opencv2"
],
"compilerPath": "C:/Program Files/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/g++.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
],
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "${fileDirname}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录 "program": "e:/HJL/C++/opencv0405/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "C:/Program Files/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/gdb.exe",
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
settings.json 不重要
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wconversion",
"-Wnull-dereference",
"-Wsign-conversion"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "g++",
"command": "C:/Program Files/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/g++.exe",
"args": [
"-g",
"-std=c++17",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-I",
"E:/Cpp/C++/opencv/build/include",
"-L",
"E:/Cpp/C++/opencv/build/x64/mingw/bin",
"-l",
"libopencv_calib3d470",
"-llibopencv_core470",
"-llibopencv_dnn470",
"-llibopencv_features2d470",
"-llibopencv_flann470",
"-llibopencv_gapi470",
"-llibopencv_highgui470",
"-llibopencv_imgcodecs470",
"-llibopencv_imgproc470",
"-llibopencv_ml470",
"-llibopencv_objdetect470",
"-llibopencv_photo470",
"-llibopencv_stitching470",
"-llibopencv_video470",
"-llibopencv_videoio470"
],
"options": {
"cwd": "C:/Program Files/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"type": "shell",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "C:/Program Files/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
""
],
"options": {
"cwd": "C:/Program Files/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}
4.还有一个关键点就是,cv imread图的时候需要是绝对路径,不然Cmake编译就需要在debug或者release里的目录下把图也放一份。