Opencv build error

Hello, I have been following a tutorial on how to install opencv from:

I have done everything exactly like the video and I reach up to building with cmake, the problem is that there are errors while building.
my system info is:

Windows 11
Cmake(using UI) 3.27.23
Opencv 4.8.0 windows exe
g++ (MinGW-W64 x86_64-ucrt-mcf-seh, built by Brecht Sanders) 13.2.0
python 3.10.7

C:\ opencv\opencv\build>mingw32-make
[ 0%] Built target opencv_dnn_plugins
[ 0%] Built target opencv_highgui_plugins
[ 2%] Built target jsimd
[ 4%] Built target libopenjp2
[ 4%] Built target opencv_videoio_plugins
[ 5%] Built target zlib
[ 11%] Built target opencv_core
[ 16%] Built target opencv_imgproc
[ 18%] Built target libjpeg-turbo
[ 21%] Built target libtiff
[ 27%] Built target libwebp
[ 28%] Built target libpng
[ 34%] Built target IlmImf
[ 36%] Built target opencv_imgcodecs
[ 36%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_obsensor/obsensor_uvc_stream_channel.cpp.obj
In file included from C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:41,
from C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_uvc_stream_channel.cpp:33:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:145:42: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
106 | _COM_SMARTPTR_TYPEDEF(T, __uuidof(T));
| ^
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:146:44: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:148:45: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:149:47: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:150:45: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:151:49: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:152:40: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of ‘class cv::obsensor::ComPtr’:
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:153:39: required from here
C:\ opencv\opencv\sources\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:106:27: error: could not convert template argument ‘cv::obsensor::ComPtr::__T_IID_getter’ from ‘const IID& (cv::obsensor::ComPtr::)()’ {aka ‘const GUID& (cv::obsensor::ComPtr::)()’} to ‘const IID& ()()’ {aka 'const GUID& ()()’}
C:\ opencv\opencv\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 : public IUvcStreamChannel, public IMFSourceReaderCallback
| ^~~~~~~~~~~~~~~~~
mingw32-make[2]: *** [modules\videoio\CMakeFiles\opencv_videoio.dir\build.make:241: modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_obsensor/obsensor_uvc_stream_channel.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:2598: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
mingw32-make: *** [makefile:165: all] Error 2

well, not quite, or it’s wrong (i wont even watch it)

using mingw, you need to disable MSMF related code (no support for that in mingw): in cmake:

WITH_MSMF=OFF
WITH_OBSSENSOR=OFF

clean build folder (start from scratch w. cmake) and rerun

(i also think, you got the wrong mingw, it might lack support for posix threads / mutex, but idk this one…)

please also take a look, which libpython version is shipped with your mingw (maybe you can only link against python3.8)

Amazing! That fixed it, I’ve been running some test codes and it seems to work fine.
Thanks!

1 Like

hey, nice to hear !

still, since you’re using a relatively unknown compiler,
could you add the output of cv::getBuildInformation() (or the final cmake output) here, so we can see, what you’ve got now
(intrinsics, threads and whatnot) ? much appreciated !

Sure! I hope this is helpful:

General configuration for OpenCV 4.8.0 =====================================
Version control: unknown

Platform:
Timestamp: 2023-08-31T10:08:06Z
Host: Windows 10.0.22621 AMD64
CMake: 3.27.3
CMake generator: MinGW Makefiles
CMake build tool: C:/Mingw-w64/winlibs-x86_64-mcf-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64ucrt-11.0.1-r2/mingw64/bin/mingw32-make.exe
Configuration: Release

CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (18 files): + SSSE3 SSE4_1
SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (37 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

C/C++:
Built as dynamic libs?: YES
C++ standard: 11
C++ Compiler: C:/Mingw-w64/winlibs-x86_64-mcf-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64ucrt-11.0.1-r2/mingw64/bin/x86_64-w64-mingw32-g++.exe (ver 13.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:/Mingw-w64/winlibs-x86_64-mcf-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64ucrt-11.0.1-r2/mingw64/bin/x86_64-w64-mingw32-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 stitching ts video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java python2 python3
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: YES
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.2.0)
JPEG 2000: build (ver 2.5.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)
Flatbuffers: builtin/3rdparty (23.5.9)

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

Python (for build): C:/Users/urisa/AppData/Local/Programs/Python/Python310/python.exe

Java:
ant: NO
Java: NO
JNI: NO
Java wrappers: NO
Java tests: NO

Install to: C:/ opencv/opencv/build/install

The way I compile from cmd is:
g++ opencv.cpp -I"C:\ opencv\opencv\build\include" -L"C:\ opencv\opencv\build\lib" -llibopencv_calib3d480 -llibopencv_core480 -llibopencv_dnn480 -llibopencv_features2d480 -llibopencv_flann480 -llibopencv_gapi480 -llibopencv_highgui480 -llibopencv_imgcodecs480 -llibopencv_imgproc480 -llibopencv_ml480 -llibopencv_objdetect480 -llibopencv_photo480 -llibopencv_stitching480 -llibopencv_video480 -llibopencv_videoio480

I guess there is no need to link all the libraries unless I need them, but I thought it would be a nice way of debugging whether compiling as such would work or not. Below is an example of the code I’ve tested for now.


#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>


using namespace cv;
int main()
{
    std::string image_path = "1152.jpg";
    Mat img = imread(image_path, IMREAD_COLOR);
    std::cout << getBuildInformation();
    imshow("Display window", img);
    int k = waitKey(0); // Wait for a keystroke in the window
    return 0;
}

1 Like