具体关于mingw,cmake之类的下载配置见:
写的很详细了,注意看完(一)后还有(二)
我这里就写下配置json文件的结果(搞了几个小时才搞定)。
总之就一句话: 一定要使用default生成的json文件来改!!!
不要从各种博客上借鉴改来改去,每个人的vscode版本都不一样,default生成的json文件都不一样,其实需要改的地方很少,只需要在task.json和c_cpp_properties.json上加上路径即可;
这个不需要修改,在一个文件夹内open with vscode后会自动生成.vscode文件,然后新建一个.cpp文件,debug就会自动生成launch.json,完全不需要修改,用default的配置即可;
(如果需要显示powershell窗口输出的话,可以设置 “externalConsole”: true,
这里默认是false)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: 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",
// 从这里开始修改,改成自己的路径
"-I",
"D:/Software/open-cv/opencv/build/include",
"-I",
"D:/Software/open-cv/opencv/build/include/opencv",
"-I",
"D:/Software/open-cv/opencv/build/include/opencv2",
"-L",
"D:/Software/open-cv/opencv/build/x64/MinGW/lib",
// 这里注意要换成自己安装的opencv的版本号,很多种方式查看,百度即可
"-l", "libopencv_core3413",
"-l", "libopencv_imgproc3413",
"-l", "libopencv_video3413",
"-l", "libopencv_ml3413",
"-l", "libopencv_highgui3413",
"-l", "libopencv_objdetect3413",
"-l", "libopencv_flann3413",
"-l", "libopencv_imgcodecs3413",
"-l", "libopencv_photo3413",
"-l", "libopencv_videoio3413"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
// 只需要在这里添加自己的路径即可
"D:/Software/open-cv/opencv/build/include",
"D:/Software/open-cv/opencv/build/include/opencv",
"D:/Software/open-cv/opencv/build/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}