How to install relevant shared libraries along with executionable using cmake

Hi,
i’m trying to build and install an executionable file that uses OpenCV. To build, install and package I use CMake and CPack. Here is my problem:

In the cmake list, i have added the executionable, open cv is found and linked.

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS}) 
add_executable(MyApp src/MyApp.cpp) 
target_link_libraries(MyApp ${OpenCV_LIBS}) 

The project can build, however the shared libraries are not installed. I would love for the build/install folder to look something like this:

bin/
    MyApp
lib/
    libopencv-calib3d.so
    ...

Right now only the bin folder is created when I run the installation.
Hope someone can help.

Kind regards
Peter

Hi, I’m trying to do the same thing but I can’t find a way to do it. I can successfully package my program but then when I go to install it I get an error saying

Error: 
 Problem: conflicting requests
  - nothing provides libopencv_core.so.405()(64bit) needed by MyProgram-0.1.0-1.x86_64

It’s really frustrating that there’s absolutely no documentation on how to package opencv as a dependency.

typo? I would expect 455 (current version). no idea what 405 could mean.

No, it’s not a typo. It’s copied straight from the error message.

Some time after my original message I managed to fix the issue. Now I reinstalled my OS and need to reinstall OpenCV too, but I’m faced with the same problem again and I don’t remember what I did to fix it since it was more than a year ago…

I should mention that I’m installing OpenCV from the source and not with my package manager (dnf).

please also consider building static opencv libs, & linking your prog against those, so you end up with a single executable & no dep libs.

That would be ideal since I wouldn’t need to install OpenCV every time, but I never did anything similar and don’t know where to start with CMake and CPack.

use BUILD_SHARED_LIBS=OFF in cmake, when building opencv libs (no CPack or such step involved)

I tried doing that but the generated package still shows the same error… Am I doing it wrong?

This is the command I used to build it
cmake . -B build/ -D BUILD_SHARED_LIBS=OFF && cmake --build build/
and then
cd build/ && cpack

sorry, but i have no idea, what cpack does, never used that.

CPack is used to generate an installable RPM package of your application. And I think the issue lies there since CMake has no trouble finding OpenCV. In fact when I build the project this line gets printed to the terminal:
-- Found OpenCV: /usr/local (found version "4.8.0") found components: core imgcodecs imgproc

To add to this. I can install the application without issues with make like this: make -j$(nproc) && sudo make install. It’s only the RPM file that CPack generates that doesn’t work…

sounds like some “friendly person” added support for this, but never maintained it …

all in all – i think, trying to redistribute opencv libs on your own is a terrible idea.
getting 3rd party deps right on different os’es or even local hardware optimizations is next to impossible, imo.

instruct ppl how to build opencv libs locally, and how to link your prog, much better !

Yeah, that’s what I was doing up until now… My README.md clearly states that it needs OpenCV to work and that the user should install it on their own before proceeding.