嗯。想着用c++来学习opencv,但是一上手做在配置环境上就遇到问题了,花了一天时间才解决,记录一下,下次配置的时候可以参考。
1.文件的下载
下载的gcc编译器:https://sourceforge.net/projects/mingw-w64/files/mingw-w64/
这里我下载的是:x86_64-posix-seh。使用别的版本时会出现各种问题,对作为新手的我来说,太不友好了。
这里再提一下,用于windows下的gcc编译器主要有这几类:Cygwin 、 MinGW、mingw-w64 。Cygwin没有用过,在用MinGW时会出现不支持c++线程的问题。这里附上下载地址:https://gcc.gnu.org/install/binaries.html
下载opencv:https://github.com/huihut/OpenCV-MinGW-Build
2.项目配置文件
#launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"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": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
#c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"c:\\OpenCV-MinGW-Build\\include",
"c:\\OpenCV-MinGW-Build\\include\\opencv2",
"c:\\OpenCV-MinGW-Build\\include\\opencv"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
总结
配置时出现的问题一般都是使用的文件版本不对,对各种的不支持。非常感谢那些提出问题和解决问题的人,我才能去参考它们的文章、回答,最终解决问题。这里附上参考的一些网站:
https://ithelp.ithome.com.tw/questions/10193134
https://github.com/chenyus0609/opencv-configuration-with-vscode
http://harryshaun.wang/mingw-w64seh%E8%BF%98%E6%98%AFsjlj/
在最后还遇到了一个问题:
将需要链接的库文件复制到
C:\Windows\SysWOW64
C:\Windows\System32