函式庫的rpath
linker設定rpath的選項範例如下
1 | gcc -Wl,-rpath=/opt/nvidia/deepstream/deepstream-6.4/lib test.cpp |
RPATH有一個特殊識別符號$ORIGIN,表示執行檔的所在目錄
1 | gcc -Wl,-rpath='$ORIGIN/../lib' test.cpp |
查看函式庫的rpath
1 | readelf -d libnvds_rest_server.so |head -20 |
或是
1 | objdump -x libnvds_rest_server.so |grep 'R.*PATH' |
CMake使用兩個變數來控制RPATH:INSTALL_RPATH和BUILD_RPATH,install步驟的rpath是INSTALL_RPATH
1 | SET_TARGET_PROPERTIES(nvds_rest_server |
cmake的另一個設定RPATH的方法
https://discourse.cmake.org/t/library-rpath-resolution/887/7
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH “${ORIGIN}”)