0

I'm using vcpkg to install OpenCV4 on Windows. But when I try to link my application, one of the OpenCV classes I'm using is giving me trouble:

2>main.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::VideoWriter::VideoWriter(void)" (??0VideoWriter@cv@@QEAA@XZ) referenced in function main
2>main.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl cv::VideoWriter::~VideoWriter(void)" (??1VideoWriter@cv@@UEAA@XZ) referenced in function main
2>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __cdecl cv::VideoWriter::open(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,double,class cv::Size_<int>,bool)" (?open@VideoWriter@cv@@UEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HNV?$Size_@H@2@_N@Z) referenced in function main

So I'm thinking I need to enable a non-default feature. OpenCV was originally installed like this:

vcpkg install --triplet x64-windows-static-md opencv4

By default, this seems to install [dnn,jpeg,opengl,png,tiff,webp].

I've also tried adding a few more of the optional features, including:

vcpkg install --triplet x64-windows-static-md opencv4[core,jpeg,opengl,png,tiff,webp,ffmpeg,openmp]

Output:

...cut...
The package opencv4:x64-windows-static-md provides CMake targets:

find_package(OpenCV CONFIG REQUIRED)
# Note: 14 target(s) were omitted.
target_link_libraries(main PRIVATE quirc opencv_ml libprotobuf opencv_core)

I'm using the vcpkg toolchain file when calling cmake to create the project. And the relevant portion of my CMakeLists.txt file contains the following as instructed by vcpkg:

FIND_PACKAGE(OpenCV CONFIG REQUIRED)
INCLUDE_DIRECTORIES ( BEFORE ${OpenCV_INCLUDE_DIRS} )
ADD_EXECUTABLE ( mytest main.cpp )
TARGET_LINK_LIBRARIES ( mytest PRIVATE quirc opencv_ml libprotobuf opencv_core )

Part of the problem is the vcpkg ports/opencv4/control file contains probably 20 optional features, and the descriptions are nearly useless.

My question:

Anyone know what vcpkg feature is needed to get access to the cv::VideoWriter class, or what to look for in the code so I can figure out which optional feature is required?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Stéphane
  • 19,459
  • 24
  • 95
  • 136
  • 1
    The response [here](https://stackoverflow.com/a/25876738/3987854) claims this class is defined in `videoio`, so you might add `opencv_videoio` to your list of linked libraries in CMake. That may work, of course, if vcpkg pulled in that package. – Kevin Jul 15 '20 at 20:52
  • Something I just discovered: the names of the various link targets is in a file named `OpenCVModules.cmake`. For example, on my system I found that file at `vcpkg\packages\opencv4_x64-windows-static-md\share\opencv\OpenCVModules.cmake`. – Stéphane Jul 19 '20 at 22:50

1 Answers1

1

As @squareskittles commented, the solution is due to some missing names in the TARGET_LINK_LIBRARIES line generated by vcpkg.

The solution for me was to changed this line:

TARGET_LINK_LIBRARIES ( mytest PRIVATE quirc opencv_ml libprotobuf opencv_core )

...to instead look like this:

TARGET_LINK_LIBRARIES ( mytest PRIVATE quirc opencv_ml libprotobuf opencv_core opencv_videoio )

And in one of my other test apps, I also had to add opencv_highgui. Looks like the "target" lines generated by vcpkg don't contain everything needed.

Stéphane
  • 19,459
  • 24
  • 95
  • 136