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

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 close merge delete

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