OpenCV CMake openCV building error

Hello Everyone,

I am a bit stuck, I checked similar posts but did not find any working solutions. I am using OpenCV with C++ under QT for about 2 years. Today I tried to migrate to CMake and VS code. But I am not able to build a simple application. Always got the same results and error messages:

opencv2/core/utility.hpp:714:14: error: 'recursive_mutex' in namespace 'std' does not name a type

I am using it with windows, OpenCV 4.2 version, CMake version 3.17, for compiling GCC 9.2 . I am out of ideas, as much I know these components compatible with each other.

I would be grateful any kind of help.

far too old.
please use current 4.7,.0, so we’re on the same page

must be some kind of mingw ? what exactly ?
(does it have posix threads ?)

Yes it’s gcc (MinGW.org GCC Build-20200227-1) 9.2.0. I downloaded the 4.7 opencv version. But when i try to build with cmake it always ends near 50% with [Makefile:179: all] Error 2 code. I checked the code and possible errors changed my python version from 3.10 to 3.7. I am not understand how can the configuration wrong because I used the same steps when I built the previous OpenCV version.

again, the problem is not the opencv (or even python) version, but your compiler, which does not have support for posix threads on win (thus the errors about mutex).

try Downloads - MinGW-w64 ,
and make sure to pick the one with posix threads !

I have downloaded the x86_64-12.2.0-release-posix-seh-ucrt-rt_v10-rev2, added to the path and repeated the configuration and building with the same results. The building process always breaks at the opencv_dnn module. Really not understand what changed the last time I built it with opencv.

well, it worked for me ;(

did you clean the build folder ? (cmakecache.txt) ?
did cmake ask you to specify your compiler ?
are you 100% sure, it’s using the new compiler ?

how much RAM do you have?

where’s the complete build log?

16 GB, can I run out of memory during the build?
The build log is about 2000+ lines how can I attach it effectively?
I found a problem in the CMake gui:

BlockquoCMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
directory
Call Stack (most recent call first):
CMakeLists.txt:1059 (include)

and the general configuration:

General configuration for OpenCV 4.7.0-dev =====================================
Version control: unknown

Platform:
Timestamp: 2023-01-11T14:07:58Z
Host: Windows 10.0.19044 AMD64
CMake: 3.17.0
CMake generator: MinGW Makefiles
CMake build tool: C:/mingw64/bin/mingw32-make.exe
Configuration: Release

C/C++:
Built as dynamic libs?: YES
C++ standard: 11
C++ Compiler: C:/mingw64/bin/g++.exe (ver 12.2.0)
C++ flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: C:/mingw64/bin/gcc.exe
C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,–gc-sections
Linker flags (Debug): -Wl,–gc-sections
ccache: NO
Precompiled headers: NO
Extra dependencies: pthread
3rdparty dependencies:

OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching ts video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java python2
Applications: tests perf_tests apps
Documentation: NO
Non-free algorithms: NO

Windows RT support: NO

GUI: WIN32UI
Win32 UI: YES
VTK support: NO

Media I/O:
ZLib: build (ver 1.2.13)
JPEG: build-libjpeg-turbo (ver 2.1.3-62)
SIMD Support Request: YES
SIMD Support: NO
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.2.0)
JPEG 2000: build (ver 2.4.0)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES

Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES

Parallel framework: pthreads

Trace: YES (built-in)

Other third-party libraries:
Lapack: NO
Eigen: NO
Custom HAL: NO
Protobuf: build (3.19.1)

OpenCL: YES (NVD3D11)
Include path: C:/opencv47/sources/3rdparty/include/opencl/1.2
Link libraries: Dynamic load

Python 3:
Interpreter: C:/Program Files/Python37/python.exe (ver 3.7.5)
Libraries: C:/Program Files/Python37/libs/libpython37.a (ver 3.7.5)
numpy: C:/Program Files/Python37/lib/site-packages/numpy/core/include (ver 1.19.5)
install path: C:/Program Files/Python37/Lib/site-packages/cv2/python-3.7

Python (for build): C:/Program Files/Python37/python.exe

Java:
ant: NO
JNI: C:/Program Files/Eclipse Adoptium/jdk-8.0.312.7-hotspot/include C:/Program Files/Eclipse Adoptium/jdk-8.0.312.7-hotspot/include/win32 C:/Program Files/Eclipse Adoptium/jdk-8.0.312.7-hotspot/include
Java wrappers: NO
Java tests: NO

Install to: C:/opencv47/build/install

you’re safe to ignore this, it’s trying to setup a script for VS, irrelevant for mingw

After checking the build log I found this error messages:

               from C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_uvc_stream_channel.cpp:33:
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IMFAttributes>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:145:42:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IMFAttributes>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IMFAttributes>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IMFAttributes>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
  106 |     _COM_SMARTPTR_TYPEDEF(T, __uuidof(T));
      |                           ^
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IMFMediaSource>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:146:44:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IMFMediaSource>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IMFMediaSource>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IMFMediaSource>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IMFSourceReader>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:148:45:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IMFSourceReader>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IMFSourceReader>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IMFSourceReader>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IAMCameraControl>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:149:47:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IAMCameraControl>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IAMCameraControl>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IAMCameraControl>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IAMVideoProcAmp>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:150:45:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IAMVideoProcAmp>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IAMVideoProcAmp>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IAMVideoProcAmp>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IKsTopologyInfo>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:151:49:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IKsTopologyInfo>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IKsTopologyInfo>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IKsTopologyInfo>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IUnknown>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:152:40:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IUnknown>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IUnknown>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IUnknown>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr<IKsControl>':
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:153:39:   required from here
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument 'cv::obsensor::ComPtr<IKsControl>::__T_IID_getter' from 'const IID& (cv::obsensor::ComPtr<IKsControl>::)()' {aka 'const GUID& (cv::obsensor::ComPtr<IKsControl>::)()'} to 'const IID& (*)()' {aka 'const GUID& (*)()'}
C:\opencv47\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:129:7: warning: base class 'struct IMFSourceReaderCallback' has accessible non-virtual destructor [-Wnon-virtual-dtor]
  129 | class MSMFStreamChannel[ 50%]  : public IUvcStreamChannel, public IMFSourceReaderCallback
      |       Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/opencv_videoio_main.cpp.obj^~~~~~~~~~~~~~
I also double checked the compiler it could build properly the following code snippet:
```
#include <stdio.h>

#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

int main(){
    cv::namedWindow("Output",1);
    
    //initialize a 120X350 matrix of black pixels:
    cv::Mat output = cv::Mat::zeros( 120, 350, CV_8UC3 );
    //display the image:
    cv::imshow("Output", output);
    //wait for the user to press any key:
    cv::waitKey(0);
    
}
Does not that mean this compiler version supports the multithreading functions?
```

mingw does not have code for MSMF, you need to disable it:

WITH_MSMF=OFF  WITH_OBSENSOR=OFF

in cmake

1 Like

Thank you that was the problem, now the building is finished without error only the install folder missing, the content of the include folder and the lib folder is equivalent with the install folder. Am I still misconfiguring or the content of the build folder is enough without the install folder(Build folder also contains a include folder with the headers and a bin folder with the dlls)?

mingw32-make install

(then you have everything you need in build\install)

1 Like

Thank you! That was instructive, I need to read more before the questioning something.
Have a nice day!

1 Like