4

I am using visual studio code on Ubuntu 20.04 and cmake tools for visual studio code.

I am trying to use opencv in a project. I used vcpkg to build OpenCV and it is installed:

The cmakeList.txt is as follow:

cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_TOOLCHAIN_FILE /home/m/vcpkg/scripts/buildsystems/vcpkg.cmake)
project(testcmake VERSION 0.1.0)

include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)

add_executable(testcmake main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

I also added this line to setting.json:

{
    "cmake.configureOnOpen": false,
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",

    "cmake.configureSettings": {
      "CMAKE_TOOLCHAIN_FILE": "/home/m/vcpkg/scripts/buildsystems/vcpkg.cmake"
    }
  }

but when I run cmake, I am getting this error:

[main] Building folder: cmakeTest 
[main] Configuring folder: cmakeTest 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=/home/m/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/gcc-9 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/g++-9 -H/home/m/MyData/sourceCode/cmakeTest -B/home/m/MyData/sourceCode/cmakeTest/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/m/MyData/sourceCode/cmakeTest/build/CMakeFiles/CMakeOutput.log".
[cmake] CMake Error at CMakeLists.txt:7 (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] 

Why make can not find opencv using vcpkg?

Edit 1

I compiled OpenCV for x64:

opencv4:x64-linux                                  4.3.0#1          computer vision library
opencv4[dnn]:x64-linux                                              Enable dnn module
opencv4[jpeg]:x64-linux                                             JPEG support for opencv
opencv4[opengl]:x64-linux                                           opengl support for opencv
opencv4[png]:x64-linux                                              PNG support for opencv
opencv4[tiff]:x64-linux                                             TIFF support for opencv
opencv4[webp]:x64-linux                                             WebP support for opencv
opencv:x64-linux                                   4.3.0            Computer vision library
opencv[dnn]:x64-linux                                               Enable dnn module
opencv[jpeg]:x64-linux                                              JPEG support for opencv
opencv[opengl]:x64-linux                                            opengl support for opencv
opencv[png]:x64-linux                                               PNG support for opencv
opencv[tiff]:x64-linux                                              TIFF support for opencv
opencv[webp]:x64-linux                                              WebP support for opencv

I know that I should set the vcpkg triplets, how can I set it by default so all applications use it instead of putting it in cmake?

Update 2

I set the triplets as following but still getting the same error:

cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_TOOLCHAIN_FILE /home/m/vcpkg/scripts/buildsystems/vcpkg.cmake)
set(VCPKG_TARGET_TRIPLET x64-linux CACHE STRING "VCPKG Target Triplet to use")
project(testcmake VERSION 0.1.0)

include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)

add_executable(testcmake main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
mans
  • 17,104
  • 45
  • 172
  • 321
  • have you checked for which platform do you compile - like x86 or x64? – Bernd Nov 14 '20 at 22:36
  • the default is x86 on my machine - but I usually compile for x64... You should find the openCV files at %VC_PACKAGE%\vcpkg\installed\%PLATFORM%\include – Bernd Nov 14 '20 at 22:40
  • @Bernd Please see updated section. I compiled for x64. Can I set this and toolchain globally so I don't need to do this per cmake? – mans Nov 15 '20 at 18:58
  • you could use an enviroment variable: https://vcpkg.readthedocs.io/en/latest/users/integration/#using-an-environment-variable-instead-of-a-command-line-option – Bernd Nov 15 '20 at 19:10
  • Have you checked that the x64 linux version is installed? – Bernd Nov 15 '20 at 19:12
  • @Bernd Not sure what do you mean? As I showed above the openCV with x64-linux is installed by vcpkg. Do I need to install something else? – mans Nov 15 '20 at 19:14
  • 2
    You should try to delete the CMakeCache. Edit 1 shows the output of `vcpkg list`, right? So it seems to be installed corretly. – Bernd Nov 15 '20 at 19:56
  • 1
    I tried it my self and could reproduce the error while I had not installed the package. But after install and cleanup my build dir it works. – Bernd Nov 15 '20 at 20:15
  • First of all change `cmake_minimum_required(VERSION 3.0.0)` to at least `cmake_minimum_required(VERSION 3.15)`. vcpkg internally is using 3.18 so you might use that. Please check if there is `vpckgroot`/installed/x64-linux/share/opencv/` or similiar and post the exact casing of any `OpenCVConfig.cmake` or similar you find – Alexander Neumann Nov 16 '20 at 09:43

0 Answers0