前置步骤这里就不细说的,注意关键的时MinGW安装的时候要不要选择win32,选那个pox什么的,不然会在2%就报错然后说一下这次的重点,按个这里使用到了四个配置,主要针对问题是opencv可以转到定义但是无法编译
话不多说,直接贴出四个配置
首先是c_cpp_properties.json,注意一共需要修改两个地方,
1.首先是IncludePath,有的教程中可能会让你添加include/c++,但实际测试下来应该是版本问题,所以没关系
2.然后是compilerPath,这里没什么好说,冲就完事
//c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/opencv/build/include",
"D:/opencv/build/include/opencv",
"D:/opencv/build/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "D:/mingw64/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
然后是launch.json,这里修改的主要是一个地方,就是miDebuggerPath
//launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
然后是setting.json,这里新建一个就行,内容如下,无需修改
//setting.json
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"ratio": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
}
}
最后是task.json,注意!!!!!!,这里网上很多的教程由于opencv版本限定到了那几个,所以大多没对版本信息进行修改,因而这里其实修改的并不只有路径,除了路径还有libopencv_xxx那块的版本,就是后面的3xxx改成你的版本
//tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D:/opencv/build/include",
"-I",
"D:/opencv/build/include/opencv",
"-I",
"D:/opencv/build/include/opencv2",
"-L",
"D:/opencv/build/x64/MinGW/lib",
"-l", "libopencv_core3415",
"-l", "libopencv_imgproc3415",
"-l", "libopencv_video3415",
"-l", "libopencv_ml3415",
"-l", "libopencv_highgui3415",
"-l", "libopencv_objdetect3415",
"-l", "libopencv_flann3415",
"-l", "libopencv_imgcodecs3415",
"-l", "libopencv_photo3415",
"-l", "libopencv_videoio3415"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
以上就是本篇文章的全部内容,建议与这篇文章配合使用,注意!!!!!!!!请使用f5编译!!!
有问题随时留言,我每天都在