First of all, I am currently using Mingw-w64 version 13.2.0, cmake 3.28.3 and OpenCV version 4.8.0, Windows 10 and Visual Studio Code as the IDE. The project in question just has a main.cpp file in it whose sole purpose is to type “Hello” in the console; so, the libraries are not called with include inside it. While trying to build the project with the following command and cmakelists.txt file, cmake wont build it, giving the following error: cmake.EXE --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=…\mingw13.2.0\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=…\mingw13.2.0\bin\g++.exe -S…/dems -B…/build -G “MinGW Makefiles” CMakelists.txt:
cmake_minimum_required(VERSION 3.28.3)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(proj VERSION 1.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} .../vcpkg/installed/x86-windows/share/opencv)
find_package(OpenCV REQUIRED)
include(.../vcpkg/scripts/buildsystems/vcpkg.cmake)
add_executable(main main.cpp)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
Output:
[cmake] CMake Error at CMakeLists.txt:11 (find_package):
[cmake] By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
[cmake] asked CMake to find a package configuration file provided by "OpenCV", but
[cmake] CMake did not find one.
[cmake]
[cmake] Could not find a package configuration file provided by "OpenCV" with any
[cmake] of the following names:
[cmake]
[cmake] OpenCVConfig.cmake
[cmake] opencv-config.cmake
[cmake]
[cmake] Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
[cmake] "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
[cmake] provides a separate development package or SDK, be sure it has been
[cmake] installed.
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: ... -G "MinGW Makefiles" exited with code: 1
Then, I did what it told me to do and added the following line right under set(CMAKE_MODULE_PATH …) set(OpenCV_DIR .../vcpkg/installed/x86-windows/share/opencv)
After doing this, it gave me the following error:
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at .../CMake3.28.3/share/cmake-3.28/Modules/CMakeFindDependencyMacro.cmake:76 (find_package):
[cmake] Could not find a package configuration file provided by "Protobuf" with any
[cmake] of the following names:
[cmake]
[cmake] ProtobufConfig.cmake
[cmake] protobuf-config.cmake
[cmake]
[cmake] Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
[cmake] "Protobuf_DIR" to a directory containing one of the above files. If
[cmake] "Protobuf" provides a separate development package or SDK, be sure it has
[cmake] been installed.
[cmake] Call Stack (most recent call first):
[cmake] .../vcpkg/installed/x86-windows/share/opencv/OpenCVModules.cmake:19 (find_dependency)
[cmake] .../vcpkg/installed/x86-windows/share/opencv/OpenCVConfig.cmake:126 (include)
[cmake] CMakeLists.txt:11 (find_package)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: ...\CMake3.28.3\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=...\mingw13.2.0\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=...\mingw13.2.0\bin\g++.exe -S.../dems-B.../dems/build -G "MinGW Makefiles" exited with code: 1
After adding the following line to the cmake file I got the following error: set(Protobuf_DIR .../vcpkg/installed/x64-windows/share/protobuf)
(I was advised that I shouldn’t have used the x86 version and installed the x64 version instead and also removed the include(…) command and instead used set(CMAKE_TOOLCHAIN_FILE …/buildsystems/vcpkg.cmake) near the top of the cmakelists file and got the following error instead:
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at .../CMake3.28.3/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake] Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
[cmake] Call Stack (most recent call first):
[cmake] .../CMake3.28.3/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
[cmake] .../CMake3.28.3/share/cmake-3.28/Modules/FindTIFF.cmake:272 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
[cmake] .../CMake3.28.3/share/cmake-3.28/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
[cmake] .../vcpkg/installed/x64-windows/share/opencv/OpenCVModules.cmake:35 (find_dependency)
[cmake] .../vcpkg/installed/x64-windows/share/opencv/OpenCVConfig.cmake:126 (include)
[cmake] CMakeLists.txt:17 (find_package)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: ...\CMake3.28.3\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=...\mingw13.2.0\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=...\mingw13.2.0\bin\g++.exe -S .../dems -B.../dems/build -G "MinGW Makefiles" exited with code: 1
I also checked the …/vcpkg/installed/x64-windows/share folder and Tiff is in fact there, so it is installed.
I tried an older version of mingw(8.1) but i obtained the same result. Am I doing something wrong in the cmake file? I started using cmake and vcpkg only a week ago, so I still am kinda new at it. However, I also installed and then used ffmpeg using vcpkg with a similar cmake file, which worked without a problem.
Lastly, I tried to use the visual studio compiler, it also asked me to set OpenCV_DIR and then the Protbuf_DIR as usual. However, when I compiled it, it did not raise an error and it allowed me to use opencv inside the main.cpp file, without any squiggles. However, I still would like to use Mingw to compile.
Also, why do I need to set Protbuf_DIR? I saw that OpenCV_DIR needs to be set; however, I did not really see something about having to set Protbuf_DIR.