How to resolve the 2 fatal errors below?

I’m trying to build and install the OpenCV library on my windows os system using Cmake and MinGW.

Got the error below while the run the command “mingw32-make” on the command prompt:

C:\OpenCV>mingw32-make [ 2%] Built target zlib [ 2%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.obj C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:40:18: error: 'mutex' in namespace 'std' does not name a type mutable std::mutex mtx; ^~~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:41:18: error: 'condition_variable' in namespace 'std' does not name a type mutable std::condition_variable cond_var; ^~~~~~~~~~~~~~~~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp: In member function 'bool cv::AsyncArray::Impl::get(cv::OutputArray, int64) const': C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:91:26: error: 'mutex' is not a member of 'std' std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:91:26: error: 'mutex' is not a member of 'std' C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:91:36: error: template argument 1 is invalid std::unique_lockstd::mutex lock(mtx); ^ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:91:43: error: 'mtx' was not declared in this scope std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:91:38: warning: unused variable 'lock' [-Wunused-variable] std::unique_lockstd::mutex lock(mtx); ^~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp: In member function 'bool cv::AsyncArray::Impl::wait_for(int64) const': C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:148:26: error: 'mutex' is not a member of 'std' std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:148:26: error: 'mutex' is not a member of 'std' C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:148:36: error: template argument 1 is invalid std::unique_lockstd::mutex lock(mtx); ^ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:148:43: error: 'mtx' was not declared in this scope std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:151:20: error: 'cond_var' was not declared in this scope return cond_var.wait_for(lock, std::chrono::nanoseconds(timeoutNs), cond_pred); ^~~~~~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:154:13: error: 'cond_var' was not declared in this scope cond_var.wait(lock, cond_pred); ^~~~~~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp: In member function 'void cv::AsyncArray::Impl::setValue(cv::InputArray)': C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:178:26: error: 'mutex' is not a member of 'std' std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:178:26: error: 'mutex' is not a member of 'std' C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:178:36: error: template argument 1 is invalid std::unique_lockstd::mutex lock(mtx); ^ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:178:43: error: 'mtx' was not declared in this scope std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:196:9: error: 'cond_var' was not declared in this scope cond_var.notify_all(); ^~~~~~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:178:38: warning: unused variable 'lock' [-Wunused-variable] std::unique_lockstd::mutex lock(mtx); ^~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp: In member function 'void cv::AsyncArray::Impl::setException(std::__exception_ptr::exception_ptr)': C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:206:26: error: 'mutex' is not a member of 'std' std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:206:26: error: 'mutex' is not a member of 'std' C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:206:36: error: template argument 1 is invalid std::unique_lockstd::mutex lock(mtx); ^ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:206:43: error: 'mtx' was not declared in this scope std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:215:9: error: 'cond_var' was not declared in this scope cond_var.notify_all(); ^~~~~~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:206:38: warning: unused variable 'lock' [-Wunused-variable] std::unique_lockstd::mutex lock(mtx); ^~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp: In member function 'void cv::AsyncArray::Impl::setException(cv::Exception)': C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:225:26: error: 'mutex' is not a member of 'std' std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:225:26: error: 'mutex' is not a member of 'std' C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:225:36: error: template argument 1 is invalid std::unique_lockstd::mutex lock(mtx); ^ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:225:43: error: 'mtx' was not declared in this scope std::unique_lockstd::mutex lock(mtx); ^~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:234:9: error: 'cond_var' was not declared in this scope cond_var.notify_all(); ^~~~~~~~ C:\OpenCV-3.4.16\opencv\sources\modules\core\src\async.cpp:225:38: warning: unused variable 'lock' [-Wunused-variable] std::unique_lockstd::mutex lock(mtx); ^~~~ modules\core\CMakeFiles\opencv_core.dir\build.make:177: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.obj' failed mingw32-make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/async.cpp.obj] Error 1 CMakeFiles\Makefile2:2003: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed mingw32-make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2 Makefile:164: recipe for target 'all' failed mingw32-make: *** [all] Error 2

Request someone to kindly pls help.

The 2 errors resulted after I ran the mingw32-make command.

do you have that output with correct line breaks too?

@crackwitz Hers’s the output (1/2)

@crackwitz Here’s the second half of the output.


I got the errror above with a different verion of OpenCV(3.4.3) while I was trying to build the library with Cmake and MinGW, Kindly pls help me resolve this error @crackwitz

opencv 3.4.3 is far too old (frozen, can’t be fixed), don’t use that.

please report:

g++ --version

(it might be unusable to compile this.
you need a mingw64 with posix-threads enabled,
so it has the correct ‘mutex’ headers)

@berak

C:\Users\Nikhil>g++ --version
g++ (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I’m unable to find the link for MinGW installer wherein I can specify the threads as posix-threads along with other setup settings on the image attached.

1 Like

I got the same error when I was trying to build a newer verion of OpenCv (3.4.16) which was released on 2021-10-11.

@berak Request you kindly help resolve the errors.

see: [resolved]A question about installation 4.7.0 - #9 by cqbztzl
in short:

  • update your compiler
  • disable anything MSMF related
  • clear build folder & restart cmake

How do I disable anything MSMF related ?

WITH_MSMF=OFF WITH_OBSSENSOR=OFF
(see other post, please …)

also, IF you wanted to build python bindings, unfortunately it needs py <= 3.8
(later dists dont come with a mingw compatible python.a)