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

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

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

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)
set_target_properties(Kinova.API.CommLayerUbuntu
    PROPERTIES
        IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib/libKinova.API.CommLayerUbuntu.so
)

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:

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)

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

Comments

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 imagegvdhoorn ( 2019-10-19 06:26:57 -0600 )edit