ledonter
ledonter

Reputation: 1699

CMake imported library rpath

I have an IMPORTED SHARED library for and I'm linking with it via target_link_libraries (the library has IMPORTED_LOCATION set).

But then after installation in ldd output I see smth like:

path/on-dev-machine/to/libxxx.so => not found

instead of just

libxxx.so => path/on-testing-machine/to/libxxx.so

Why is that / how do I fix it? I'm adding lib paths to /etc/ld.so.conf.d

Sample code:

include(GNUInstallDirs)

function(add_and_install_lib lib_name location external_dep)
    if(${location} MATCHES ".*\\.so")
        add_library(${lib_name} SHARED IMPORTED) # MODULE treated as shared
    else()
        add_library(${lib_name} STATIC IMPORTED)
    endif()

    set_property(TARGET ${lib_name} PROPERTY IMPORTED_LOCATION ${location})

    add_dependencies(${lib_name} ${external_dep})
endfunction()


set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}") # this doesn't seem to help

Upvotes: 3

Views: 2466

Answers (1)

ledonter
ledonter

Reputation: 1699

If anyone cares, it was the IMPORTED_NO_SONAME property (absence of it set to TRUE) of each imported lib that forced the full path to be taken.

Also CMAKE_SKIP_RPATH and CMAKE_SKIP_INSTALL_RPATH are useful in my opinion to make sure you have clean runtime paths (not straightly related to the question but still).

Upvotes: 5

Related Questions