Errors while building a cmake c++ project that includes opencv library from vcpkg

134 Views Asked by At

While trying build a project with cmake that includes opencv from vcpkg, cmake keeps saying that it could not find a config file for opencv and after setting the location for the config file, it says the same for protobuf etc.

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 included 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/x86-windows/share/protobuf)

Output:

[proc] Executing 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"
[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 configuration file for package "Protobuf" that is
[cmake]   compatible with requested version "".
[cmake] 
[cmake]   The following configuration files were considered but not accepted:
[cmake] 
[cmake]     .../vcpkg/installed/x86-windows/share/protobuf/protobuf-config.cmake, version: 3.21.12.0 (32bit)
[cmake] 
[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

I tried an older version of mingw(8.1) and also tried to use the x64 version of opencv 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 with a similar cmake file, which worked without a problem.

So, I followed your suggestions and did the following: I removed the include(...) command and instead used set(CMAKE_TOOLCHAIN_FILE .../buildsystems/vcpkg.cmake) near the top of the cmakelists file. I also uninstalled the x86 version of opencv as suggested and reinstalled the x64 version 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 there, so it is installed(I did not install it myself, it came with opencv).

0

There are 0 best solutions below