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

**URL:** <https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537>\
**Category:** C++\
**Tags:** build, cmake\
**Created:** [February 21, 2024, 10:15pm UTC](https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537 "2024-02-21T22:15:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokalp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gokalp/32/8353_2.png) [@Gokalp](https://forum.opencv.org/u/Gokalp)\
**Post date:** [February 21, 2024, 10:15pm UTC](https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537/1 "2024-02-21T22:15:03Z")

</div>

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:

```auto
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:

```auto
[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:

```auto
[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:

```auto
[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.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [February 22, 2024, 6:59am UTC](https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537/2 "2024-02-22T06:59:32Z")

</div>

I don’t have a clue about cmake, so there.

protobuf and tiff should have come with OpenCV. their source is included with OpenCV, in the repo itself. they should have been found “trivially” because opencv is supposed to know about them.

I suspect that this is a cascading issue, started by cmake not finding your ffmpeg _properly_, i.e. you patched over that by giving some variable/path directly for just opencv while another variable/path should have been given that covers the entire cascade.

you’ll probably get some more responses. there are people here with more knowledge of cmake and opencv’s build process than I have.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 22, 2024, 6:12pm UTC](https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537/3 "2024-02-22T18:12:13Z")

</div>

> [@Gokalp](#):
>
> `[cmake] Could not find a package configuration file provided by "OpenCV"`

so, your opencv install was not found automatically, you’re supposed to have a line in your CMakeLists.txt above like:

```
set (OpenCV_DIR, "path/to/install/folder/with/those/files")

```

then, never having used vcpkg, –  
i’m not sure if that has any prebuilt binaries usable with mingw  
(rather likely, that there are only .lib files for msvc use only)  
your cmake file expects those ready made, maybe you’ll need to build the libs first for mingw, before you can run that

---

<div class="post-metadata">

**Author:** ![Gokalp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gokalp/32/8353_2.png) [@Gokalp](https://forum.opencv.org/u/Gokalp)\
**Post date:** [February 22, 2024, 7:56pm UTC](https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537/4 "2024-02-22T19:56:51Z")

</div>

Thank you for your answer, I do also think that OpenCV should point to those libraries that are included with OpenCV as it is shown in the documentation and not need me to point out where protobuf etc., or at least its config files or whatever, are installed; however, it does not for some reason. I believe I did not word the ffmpeg part right, so let me reword it: I installed ffmpeg before installing opencv just to see how vcpkg and cmake worked. It only needed me to use standart commands such as find\_package, include\_directories etc. and not something like set(FFMPEG\_DIR path/to/installation/of/ffmpeg) in order to be able to include it in the main.cpp file.

---

<div class="post-metadata">

**Author:** ![Gokalp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gokalp/32/8353_2.png) [@Gokalp](https://forum.opencv.org/u/Gokalp)\
**Post date:** [February 22, 2024, 8:09pm UTC](https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537/5 "2024-02-22T20:09:05Z")

</div>

Thank you for your answer, I did actually add the line “set(OpenCV\_DIR …)” in my CMakelists.txt file after coming across the first error message, but I believe that I messed up the format while pasting it above, which made it look like I did not add it. Lastly, I do not think that I it requires me to build the libs for mingw since ffmpeg, as I stated in the reponse just above, worked without a problem. Could it be that the 4.8.0 version of OpenCV does not work with mingw? Because I was actually following a guide on vcpkg and cmake in which the person installed an older version of opencv, cmake, mingw and vcpkg(The video was a 2022 video) which also raised the first error that needed him to add the line set(OpenCV\_DIR …); however, after adding that line It did not request him to set the directory for protobuf and worked perfectly instead.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 26, 2024, 9:30am UTC](https://forum.opencv.org/t/errors-while-building-a-cmake-c-project-that-includes-opencv-library-from-vcpkg/16537/6 "2024-02-26T09:30:28Z")

</div>

please understand, that vcpkg efforts are NOT maintained by opencv.

> [@Gokalp](#):
>
> Also, why do I need to set Protbuf\_DIR?

you shouldn’t need to, even. this is clearly a bug in the vcpkg config scripts. which protobuf, tiff or ffmpeg to choose matters at **library** build time only. if there’s e.g. an opencv\_dnn.dll, it should have protobuf already compiled in.

also, even mingw will work fine, if you ditch vcpkg, and build the libs locally, on your own.
