OpenCV Install Failure for Qt6.7.2 (procedure entry point could not be found in the dynamic link library)

I have been struggling for a week to install OpenCV in a Qt environment without success. Please let me know if you discover any potential solutions.

Environment

  • Windows11 64bit
  • Qt 6.7.3
  • Qt Creator 15.0.0
  • Cmake 3.26.4
  • OpenCV 4.10.0 (any version is fine if it works)

What I have done

  1. Download OpenCV source files from here (opencv-4.10.0-windows.exe)
  2. Extract it to C:/Opencv/opencv/opencv_4_10_0
  3. Configure with the command below:
    cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=C:/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/mingw64/bin/g++.exe C:/Opencv/opencv/opencv_4_10_0/sources
  4. Build at C:/Opencv/opencv
    cmake --build build_opencv2 --target install
  5. Add lines below to CMakeList.txt in a project
    set(OpenCV_DIR "C:/OpenCV/opencv/build_opencv2/install/x64/mingw/lib")
    find_package(OpenCV REQUIRED)
    include_directories( ${OpenCV_INCLUDE_DIRS} )
    target_link_libraries(VideoPlayer PRIVATE ${OpenCV_LIBS})
  6. Run the project in Qt Creator
  7. I got errors like this:

The procedure entry point _ZNSi5seekgESt4fposl9_MbstateE could not be found in the dynamic link library C:\OpenCV\opencv\build_opencv2\install\x64\mingw\bin\libopencv_videoio4100.dll

The issue appears when I include the following line in the header file:
cv::VideoCapture cap;

My script (most part is default setting of Qt creator):

< mainwindow.h>

#include <opencv2/opencv.hpp>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();

private:
Ui::MainWindow *ui;
cv::VideoCapture cap; # HERE!!!
};
#endif // MAINWINDOW_H

<mainwindow.cpp>

#include “mainwindow.h”
#include “./ui_mainwindow.h”

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

< main.cpp>

#include “mainwindow.h”

#include

int main(int argc, char *argv)
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

Correction:
After I extracted OpenCV source at step 2, I created build_opencv2 folder manually. And I executed the step 4 building process at C:/OpenCV/opencv, which created built files at C:/OpenCV/opencv/build_opencv2.