我有一个已导入的共享库,并通过
target_link_libraries
进行链接(该库已设置IMPORTED_LOCATION
)。但是在安装后,我在ldd
输出中看到如下内容:path/on-dev-machine/to/libxxx.so => not found
,而不是简单的libxxx.so => path/on-testing-machine/to/libxxx.so
。为什么会这样?我将库路径添加到了/etc/ld.so.conf.d
。以下是示例代码: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
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
似乎没有帮助,LD_LIBRARY_PATH
也不行,我猜问题可能是因为ldd
左边有库的完整路径而非库文件本身。你知道这可能是为什么吗? - ledonter