How to install an imported shared library the "correct" way

asked 2019-10-18 16:16:04 -0500

Pinknoise2077 gravatar image

updated 2019-10-18 17:13:44 -0500

Hi ROS community!

I am trying to install an imported shared library that I am not building myself (third-party).

For this, I am using these CMake commands:

add_library(Kinova.API.CommLayerUbuntu SHARED IMPORTED)

The problem is that this hardcodes the absolute library path in the executable and only works in the devel workspace, and not in the install workspace. I know that I can use the following command to make it work:


This command actually works and gives me a relative path to the shared library that is adjusted when I source the install workspace. However, the use of link_directories is highly discouraged and I am trying to find an alternate solution.

Please note that I don't want to install the shared library in a location like /usr/local/lib. I know that it would work, but I prefer to keep all the libraries that I need in the install directory.

Any recommendations?

P.S. I am using the ldd command to look at the path of libraries on my binary file.

edit retag flag offensive close merge delete


Just a note: this is actually a CMake "problem", not something specific to Catkin (so you may want to not limit your searches to this forum).

CMake doesn't really allow you to install(..) imported targets last time I checked.

gvdhoorn gravatar image gvdhoorn  ( 2019-10-19 06:26:57 -0500 )edit