win10 _64位系统
VSCode:官网地址
Opencv:3.4.5
Cmake:3.9.0
MinGw:MinGW-W64 GCC-8.1.0(x86_64-posix-seh)
MinGW可以在线安装,也可以直接下载文件后离线解压。
本人选择的是后者,文件下载连接如上。
下载完成后直接解压到你的安装磁盘下。
然后将解压后bin文件夹的path添加到系统环境变量。例如:D:\mingw-w64\bin。
Cmake同样是下载文件后解压到安装磁盘。
然后,将其bin文件夹的path添加到系统环境变量。例如:D:\cmake\bin。
将下载的Opencv文件解压到安装磁盘后,通过Cmake选取source路径和build路径,如下图。这里ENABLE_CXX11勾选是指支持C11。
Configure后Genrate一下。因为要是使用MinGW中的C/C++编译,所以Configure的选择如下:
C选择 D:\mingw-w64\bin\gcc.exe C ++选择 D:\mingw-w64\bin\g++.exe
管理员运行cmd后cd到D:\opencv\build\x64\MinGW文件夹下。
输入minGW32-make编译,完成编译后minGW32-make install安装。
最后,将D:\opencv\build\x64\MinGW\bin添加到系统环境变量中。
下载后,安装C/C++插件,下图中第一个。
然后,配置tasks.json、launch.json、c_cpp_properties.json这三个文件。
tasks.json:
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "g++.exe build active file", "command": "D:\\mingw-w64\\bin\\g++.exe", "args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "-I", "D:/opencv/build/x64/MinGW/install/include", "-I", "D:/opencv/build/x64/MinGW/install/include/opencv", "-I", "D:/opencv/build/x64/MinGW/install/include/opencv2", "-L", "D:/opencv/build/x64/MinGW/install/x64/mingw/lib", "-lopencv_core345", "-lopencv_imgproc345", "-lopencv_imgcodecs345", "-lopencv_video345", "-lopencv_ml345", "-lopencv_highgui345", "-lopencv_objdetect345", "-lopencv_flann345", "-lopencv_imgcodecs345", "-lopencv_photo345", "-lopencv_videoio345"], "options": { "cwd": "D:\\mingw-w64\\bin" }, "problemMatcher": ["$gcc"], "group": { "kind": "build", "isDefault": true } } ] }
launch.json:
{ "version": "0.2.0", "configurations": [ { "name": "g++.exe build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:\\mingw-w64\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ], "preLaunchTask": "g++.exe build active file" } ] }
c_cpp_properties.json:
{ "configurations": [ { "name": "win32", "includePath": ["${workspaceFolder}/**", "D:/mingw-w64/bin/c++", "D:/opencv/build/x64/MinGW/install/include", "D:/opencv/build/x64/MinGW/install/opencv", "D:/opencv/build/x64/MinGW/install/opencv2", "D:/opencv/build/x64/MinGW/install/x64/mingw/lib"], "defines": ["_DEBUG", "UNICODE", "_UNICODE"], "compilerPath": "D:\\mingw-w64\\bin\\gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 }
将以上三个文件放在一个新建的.vscode文件夹下,并且将这个文件夹与你的代码放在同一文件下,就可以F5键来调试你的程序了。