最近在windows下面用cmake编译OpenCV的项目代码,但是一直碰到找不到mutex的问题,百思不得其解,
Executing task: g++ -g -o bin/debug.exe src/main.cpp C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:697:14: error: 'recursive_mutex' in namespace 'std' does not name a type typedef std::recursive_mutex Mutex; ^~~~~~~~~~~~~~~ C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:697:9: note: 'std::recursive_mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'? C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:60:1: +#include <mutex> C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:697:9: typedef std::recursive_mutex Mutex; ^~~ C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:698:29: error: 'Mutex' is not a member of 'cv' typedef std::lock_guard<cv::Mutex> AutoLock; ^~~~~ C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:698:29: note: suggested alternative: 'Matx' typedef std::lock_guard<cv::Mutex> AutoLock; ^~~~~ Matx C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:698:29: error: 'Mutex' is not a member of 'cv' C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:698:29: note: suggested alternative: 'Matx' typedef std::lock_guard<cv::Mutex> AutoLock; ^~~~~ Matx C:\MinGW\lib\opencv\build\include/opencv2/core/utility.hpp:698:34: error: template argument 1 is invalid typedef std::lock_guard<cv::Mutex> AutoLock; ^ The terminal process terminated with exit code: 1 作者:免费且高贵 https://www.bilibili.com/read/cv19967791 出处:bilibili
查看stackoverfow里面有提到,mingw64有个POSIX的东西,觉得可以一试,就到github上重新下载mingw64
Releases · niXman/mingw-builds-binaries · GitHub
选择x86_64-12.2.0-release-posix-seh-ucrt-rt_v10-rev2.7z版本,重新reload cmakelist,再次编译,果然以上问题消失。