Mutex errors when using OpenCV in CLION. (Windows, C++)

  c++, clion, opencv, windows

CMakelist.txt:

set(CMAKE_CXX_STANDARD 23)

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable(Facial_Recognition main.cpp)

target_link_libraries( Facial_Recognition ${OpenCV_LIBS} )

Main:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main() {
    Mat image;
    image = imread("C:/Users/user/OneDrive - De Montfort University/Work/headshot.jpg");
    namedWindow("Display image", WINDOW_AUTOSIZE);
    imshow("Display Image", image);
    waitKey(0);

    return 0;

The errors I get when trying to use the above code:

[ 50%] Building CXX object
CMakeFiles/Facial_Recognition.dir/main.cpp.obj In file included from
C:/opencv/build/include/opencv2/core.hpp:3307:0,
from C:/opencv/build/include/opencv2/opencv.hpp:52,
from C:UsersuserDesktopFacial Recognitionmain.cpp:2:
C:/opencv/build/include/opencv2/core/utility.hpp:718:14: error:
‘recursive_mutex’ in namespace ‘std’ does not name a type typedef
std::recursive_mutex Mutex;
^~~~~~~~~~~~~~~ C:/opencv/build/include/opencv2/core/utility.hpp:719:25: error:
‘Mutex’ is not a member of ‘cv’ typedef std::lock_guard<cv::Mutex>
AutoLock;
^~ C:/opencv/build/include/opencv2/core/utility.hpp:719:34: error:
template argument 1 is invalid typedef std::lock_guard<cv::Mutex>
AutoLock;
^ In file included from C:/opencv/build/include/opencv2/flann/kdtree_index.h:44:0,
from C:/opencv/build/include/opencv2/flann/all_indices.h:38,
from C:/opencv/build/include/opencv2/flann/flann_base.hpp:44,
from C:/opencv/build/include/opencv2/flann.hpp:48,
from C:/opencv/build/include/opencv2/opencv.hpp:65,
from C:UsersuserDesktopFacial Recognitionmain.cpp:2: C:/opencv/build/include/opencv2/flann/heap.h:
In static member function ‘static cv::Ptrcvflann::Heap<T >
cvflann::Heap::getPooledInstance(const HashableT&, int, int)’:
C:/opencv/build/include/opencv2/flann/heap.h:191:20: error: ‘Mutex’ in
namespace ‘cv’ does not name a type
static cv::Mutex mutex;
^~~~~ C:/opencv/build/include/opencv2/flann/heap.h:192:33: error: ‘mutex’
was not declared in this scope
const cv::AutoLock lock(mutex);
^~~~~ mingw32-make.exe[3]: *** [CMakeFiles/Facial_Recognition.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Facial_Recognition.dir/all] Error
2 mingw32-make.exe[1]: *** [CMakeFiles/Facial_Recognition.dir/rule] Error 2 mingw32-make.exe: *** [Facial_Recognition] Error 2
CMakeFilesFacial_Recognition.dirbuild.make:71: recipe for target
‘CMakeFiles/Facial_Recognition.dir/main.cpp.obj’ failed
CMakeFilesMakefile2:81: recipe for target
‘CMakeFiles/Facial_Recognition.dir/all’ failed
CMakeFilesMakefile2:88: recipe for target
‘CMakeFiles/Facial_Recognition.dir/rule’ failed Makefile:123: recipe
for target ‘Facial_Recognition’ failed

Source: Windows Questions

LEAVE A COMMENT