Resolving CMake Build Errors When Integrating OpenCV with Qt Projects
Environment Configuration
Before proceeding, ensure the following environment variables are properly configured:
E:\cmake\binE:\OpenCV\opencv\build\x64\vc15\binF:\Qt\Tools\mingw730_64\binF:\Qt\5.12.4\mingw73_64\bin
Issue 1: Missing Build Program
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".
CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
Solution
Navigate to the CMake GUI interface and locate the CMAKE_MAKE_PROGRAM entry. Modify the path to point to mingw32-make.exe in your MinGW installation dierctory. After updating this path, click Configure again to regenerate the build files.
Issue 2: Qt5 Package Not Found
CMake Error at cmake/OpenCVFindLibsGUI.cmake:18 (find_package):
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files.
Solution
In the CMake GUI, locate the Qt5_DIR or CMAKE_PREFIX_PATH variable. Set its value to the Qt5 configuration directory (typically found at F:\Qt\5.12.4\mingw73_64\lib\cmake\Qt5). Click Configure again to apply the changes.
Issue 3: FFMPEG Dowlnoad Failure
CMake Warning at cmake/OpenCVDownload.cmake:202 (message):
FFMPEG: Download failed: 6;"Couldn't resolve host name"
For details please refer to the download log file:
E:/OpenCv/opencv/opencv_bulid/CMakeDownloadLog.txt
Solution
Open the CMakeDownloadLog.txt file in your build directory. The log indicates missing FFMPEG components:
opencv_videoio_ffmpeg.dllopencv_videoio_ffmpeg_64.dllf8e65dbe4a3b4eedc0d2997e07c3f3fd-ffmpeg_version.cmake
Download these files manually from the following URLs:
https://raw.githubusercontent.com/opencv/opencv_3rdparty/6152e132572dfdaa32887eabeb7199bef49b14dc/ffmpeg/opencv_videoio_ffmpeg.dll
https://raw.githubusercontent.com/opencv/opencv_3rdparty/6152e132572dfdaa32887eabeb7199bef49b14dc/ffmpeg/opencv_videoio_ffmpeg_64.dll
https://raw.githubusercontent.com/opencv/opencv_3rdparty/6152e132572dfdaa32887eabeb7199bef49b14dc/ffmpeg/ffmpeg_version.cmake
For the third file, the webpage will redirect to another URL. Save the target content as a text file, then rename it with the .cmake extension. Place all three files in the appropriate 3rdparty directory within your OpenCV source folder, ensuring the filenames match exactly.