MinGW Build Error OpenCV 4.8.0

Trying to build OpenCV 4.8.0 from source on windows with mingw, throws error at around 50%.
I tried both the gcc 13 with mcf threads and gc 12.2.0 with posix threads and seh exceptions but it throws the same error, which is related to videoio.

Cmake Configuration
ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default. Detected processor: AMD64 Found PythonInterp: C:/Python311/python.exe (found suitable version "3.11.1", minimum required is "2.7") libjpeg-turbo: VERSION = 2.1.3, BUILD = opencv-4.8.0-libjpeg-turbo libjpeg-turbo(SIMD): SIMD extensions disabled: could not find NASM compiler. Performance will suffer. Cleaning INTERNAL cached variable: TIFF_LIBRARY Cleaning INTERNAL cached variable: TIFF_INCLUDE_DIR Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR) Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.8.0-openjp2-2.5.0 OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0") Could not find OpenBLAS include. Turning OpenBLAS_FOUND off Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off Could NOT find BLAS (missing: BLAS_LIBRARIES) Could NOT find LAPACK (missing: LAPACK_LIBRARIES) Reason given by package: LAPACK could not be found because dependency BLAS could not be found.

Could NOT find Java (missing: Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE)
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT JVM)
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
Module opencv_python3 disabled because opencv_python_bindings_generator dependency can’t be resolved!
Processing WORLD modules…
module opencv_core…
Consider adding OPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int/int64_t according to your build configuration
module opencv_flann…
module opencv_imgproc…
module opencv_ml…
module opencv_photo…
module opencv_dnn…
Registering hook ‘INIT_MODULE_SOURCES_opencv_dnn’: C:/OpenCV/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
opencv_dnn: filter out cuda4dnn source code
module opencv_features2d…
module opencv_imgcodecs…
imgcodecs: OpenEXR codec is disabled in runtime. Details: OpenEXR vulnerabilities · Issue #21326 · opencv/opencv · GitHub
module opencv_videoio…
module opencv_calib3d…
module opencv_highgui…
highgui: using builtin backend: WIN32UI
module opencv_objdetect…
module opencv_stitching…
module opencv_video…
module opencv_gapi…
Processing WORLD modules… DONE
Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
Excluding from source files list: /modules/world/layers/layers_common.rvv.cpp
Excluding from source files list: /modules/world/layers/layers_common.lasx.cpp
Excluding from source files list: /modules/world/int8layers/layers_common.lasx.cpp
Excluding from source files list: /modules/world/layers/cpu_kernels/conv_depthwise.rvv.cpp
Excluding from source files list: /modules/world/layers/cpu_kernels/conv_depthwise.lasx.cpp
CMake 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:1075 (include)

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

Platform:
Timestamp: 2023-09-19T11:49:28Z
Host: Windows 6.3.9600 AMD64
CMake: 3.26.4
CMake generator: MinGW Makefiles
CMake build tool: C:/MinGW/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/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:/MinGW/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 stitching ts video videoio world
Disabled: java_bindings_generator js_bindings_generator objc_bindings_generator python_bindings_generator python_tests
Disabled by dependency: python3
Unavailable: java python2 python2
Applications: tests perf_tests apps
Documentation: NO
Non-free algorithms: NO

Windows RT support: NO

GUI:
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.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: YES (ver 3.4.0)
Custom HAL: NO
Protobuf: build (3.19.1)
Flatbuffers: builtin/3rdparty (23.5.9)

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

Python 3:
Interpreter: C:/Python311/python.exe (ver 3.11.1)
Libraries: NO
numpy: C:/Python311/Lib/site-packages/numpy/core/include (ver 1.23.5)
install path: -

Python (for build): C:/Python311/python.exe

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

Install to: C:/OpenCV/build/install

Error
The Error(s)
[ 49%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/videoio/ src/cap_obsensor/obsensor_uvc_stream_channel.cpp.obj In file included from C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream _channel_msmf.hpp:41, from C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_uvc_st ream_channel.cpp:33: C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:145: 42: required from here C:\OpenCV\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\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:146: 44: required from here C:\OpenCV\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\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:148: 45: required from here C:\OpenCV\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 I ID& (*)()' {aka 'const GUID& (*)()'} C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:149: 47: required from here C:\OpenCV\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 'cons t IID& (*)()' {aka 'const GUID& (*)()'} C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:150: 45: required from here C:\OpenCV\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 I ID& (*)()' {aka 'const GUID& (*)()'} C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:151: 49: required from here C:\OpenCV\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 I ID& (*)()' {aka 'const GUID& (*)()'} C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:152: 40: required from here C:\OpenCV\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 'con st GUID& (cv::obsensor::ComPtr::)()'} to 'const IID& (*)()' {aka 'cons t GUID& (*)()'} C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp: In instantiation of 'class cv::obsensor::ComPtr': C:\OpenCV\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:153: 39: required from here C:\OpenCV\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\modules\videoio\src\cap_obsensor\obsensor_stream_channel_msmf.hpp:129: 7: warning: base class 'struct IMFSourceReaderCallback' has accessible non-virtu al destructor [-Wnon-virtual-dtor] 129 | class MSMFStreamChannel : public IUvcStreamChannel, public IMFSourceRead erCallback | ^~~~~~~~~~~~~~~~~ mingw32-make[2]: *** [modules\world\CMakeFiles\opencv_world.dir\build.make:5951: modules/world/CMakeFiles/opencv_world.dir/__/videoio/src/cap_obsensor/obsensor_ uvc_stream_channel.cpp.obj] Error 1 mingw32-make[1]: *** [CMakeFiles\Makefile2:2313: modules/world/CMakeFiles/opencv _world.dir/all] Error 2 mingw32-make: *** [Makefile:165: all] Error 2


System is Windows 8.1 with bing. Prcessor : Intel Celeron Dual Core.

<I have tried to build 4.7.0 previously with both mingw 10 and codeblocks(mingw 8) one way or another it always has ended in termination due to error!>

unfortunately, no mingw version has code for MSMF, so you will have to do without the MSMF & OBSSENSOR backends for videoio

clean prev. build artefacts and add

WITH_MSMF=OFF
WITH_OBSSENSOR=OFF

to your cmake cmdline, rerun cmake && make

Thank You, Very much it really helped, i built without errors, but now there is another runtime error, when i start program it instantly crashes and the fault is in opencv_480world.dll, what my question is that i built with world and i thought it would make a separate world dll alongwith all others but it deleted others, so i would like to use some help building all other modules without going through all that mess again since object files are already present so its just a matter of link. Can you please tell how?

code ? error ?
dont make us guess, it’s bad enough if you do …

code is simple!

Main.cpp
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2//video.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

int main()
{
cv::VideoCapture cap(1); //if(!cap.isOpened()) throw std::runtime_error(“Can’t open camera!”);
cv::Mat frame; // = cv::Mat::zeros(640, 480, CV_8U);
cv::namedWindow(“Test”);
while(true) {
cap >> frame;
cv::imshow(“Test”, frame);

    if(cv::waitKey(20) == 27) break;
}

std::cout << "Hello, World!" << std::endl;
return 0;

}


CMakeLists.txt
cmake_minimum_required(VERSION 3.17) project(Test)

set(CMAKE_CXX_STANDARD 14)

find_package(OpenCV REQUIRED)
#message(${CMAKE_MODULE_PATH})

include_directories({OpenCV_INCLUDE_DIRS}) #set(OpenCV_LIB_PATH "{OpenCV_DIR}/lib")

add_executable(Test main.cpp)
target_link_libraries(Test ${OpenCV_LIBS})

"OpenCV/x64/mingw/bin" is in PATH!

I would just like to build modules separately because opencv_world is just too large to ship with my little projects that use at max two libraries, so if you can help with that i would be pleased, because my system is slow it already took me freaking 8**hours to build, only to realize it combined all libs into one.

indeed, you must check this ! and this:

if (frame.empty())) // ALARM !

most probably, you capture did not open, try index 0 instead

1 Like

It worked, for some reason Clion shell couldn’t see Environment variables thats why it was crashing, however my question remains same can i build with slight change to config without building it from scratch, i tried modifying Makefile and Cmake files but they are just too many. regenerating obviously starts building from very start.

easy:

cmake -DBUILD_opencv_world=OFF

i’m afraid, you’re still making wrong guesses.

if the video capture does not open, it’s because of wrong user supplied params (id, backend) at runtime, it’s not a linking problem

Thanks that really helped… yes I got that crashing part under control now.