# How to install relevant shared libraries along with executionable using cmake

**URL:** <https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969>\
**Category:** Uncategorized\
**Tags:** build, cmake\
**Created:** [January 4, 2022, 11:54am UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969 "2022-01-04T11:54:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Torrild](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/peter_torrild/32/4137_2.png) [@Peter\_Torrild](https://forum.opencv.org/u/Peter_Torrild)\
**Post date:** [January 4, 2022, 11:54am UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/1 "2022-01-04T11:54:16Z")

</div>

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.

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

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

---

<div class="post-metadata">

**Author:** ![milovangudelj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/milovangudelj/32/5386_2.png) [@milovangudelj](https://forum.opencv.org/u/milovangudelj)\
**Post date:** [June 5, 2022, 2:52pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/2 "2022-06-05T14:52:34Z")

</div>

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

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

---

<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:** [June 5, 2022, 6:18pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/3 "2022-06-05T18:18:29Z")

</div>

> [@milovangudelj](#):
>
> `.so.405`

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

---

<div class="post-metadata">

**Author:** ![milovangudelj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/milovangudelj/32/5386_2.png) [@milovangudelj](https://forum.opencv.org/u/milovangudelj)\
**Post date:** [July 30, 2023, 9:48am UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/4 "2023-07-30T09:48:54Z")

</div>

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).

---

<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:** [July 30, 2023, 1:37pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/5 "2023-07-30T13:37:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![milovangudelj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/milovangudelj/32/5386_2.png) [@milovangudelj](https://forum.opencv.org/u/milovangudelj)\
**Post date:** [July 30, 2023, 5:08pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/6 "2023-07-30T17:08:58Z")

</div>

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.

---

<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:** [July 31, 2023, 10:57am UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/7 "2023-07-31T10:57:08Z")

</div>

use BUILD\_SHARED\_LIBS=OFF in cmake, when building opencv libs (no CPack or such step involved)

---

<div class="post-metadata">

**Author:** ![milovangudelj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/milovangudelj/32/5386_2.png) [@milovangudelj](https://forum.opencv.org/u/milovangudelj)\
**Post date:** [July 31, 2023, 3:16pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/8 "2023-07-31T15:16:31Z")

</div>

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`

---

<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:** [July 31, 2023, 3:32pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/9 "2023-07-31T15:32:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![milovangudelj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/milovangudelj/32/5386_2.png) [@milovangudelj](https://forum.opencv.org/u/milovangudelj)\
**Post date:** [July 31, 2023, 4:16pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/10 "2023-07-31T16:16:53Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![milovangudelj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/milovangudelj/32/5386_2.png) [@milovangudelj](https://forum.opencv.org/u/milovangudelj)\
**Post date:** [July 31, 2023, 5:26pm UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/11 "2023-07-31T17:26:56Z")

</div>

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…

---

<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:** [August 1, 2023, 5:11am UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/12 "2023-08-01T05:11:22Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![milovangudelj](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/milovangudelj/32/5386_2.png) [@milovangudelj](https://forum.opencv.org/u/milovangudelj)\
**Post date:** [August 1, 2023, 7:33am UTC](https://forum.opencv.org/t/how-to-install-relevant-shared-libraries-along-with-executionable-using-cmake/6969/13 "2023-08-01T07:33:28Z")

</div>

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.
