Set the RUNPATH of installed shared libraries to "$ORIGIN"

This is Ubuntu 20.04.2 LTS / x86_64 / gcc 9.3.0 here.

When I build the “VTK-9.0.3”, all its shared libraries get the “RUNPATH” pointing to the "/.../build/lib" directory.

However, the “make install” resets the runtime path of all installed “/.../lib/libvtk*.so” shared libraries to "".

Could you, please, consider changing this behavior so that the “RUNPATH” of “installed” shared libraries would be set to "$ORIGIN".

Note: the python related “site-packages/vtkmodules/vtk*.so” already get the runtime path "$ORIGIN/../../../" and also the executables “bin/vtk*” get "$ORIGIN/../lib".

1 Like

Why would you need rpath to be set on installed libraries? I’ve only seen rpath with $ORIGIN when a program is bundled with its libraries so that it can be unpacked anywhere in the hierarchy.

Yes, that’s more or less my case.
I’d like to “dlopen” VTK shared libraries from a running application, and I would like to spare myself the trouble of maintaining “LD_LIBRARY_PATH”.

1 Like

You can set CMAKE_INSTALL_RPATH=$ORIGIN when building VTK to add it to every library at least.

That said, VTK probably should set it for itself at least since it does ship a “few” libraries it knows will be beside each other.

Yes, I know I can use: cmake -DCMAKE_INSTALL_RPATH="\$ORIGIN"
However, I am more thinking about the default VTK behavior.
So that, when one tries to use this software compiled by somebody else, one will not need to fight with this “problem”.

An additional quirk of manually setting such a “CMAKE_INSTALL_RPATH” is that, the installed “/.../lib/libvtk*.so” shared libraries get "$ORIGIN" but simultaneously, the python related “site-packages/vtkmodules/vtk*.so” get "$ORIGIN:$ORIGIN/../../../" and also the executables “bin/vtk*” get "$ORIGIN:$ORIGIN/../lib".

This MR adds $ORIGIN internally to the modules at least (executables will still have it as an “extra” path).

how should this work with libraries like
for building vtk its not a problem, but with something donstream uses vtk (vtl built with TBB). the downstream can’t find the TBB library.

I tried setting CMAKE_INSTALL_RPATH for TBB and VTK to the install/lib directories. things still only work when I set LD_LIBRARY_PATH to the TBB lib directory.

I saw this post [ vtk shared library lookup on linux](vtk shared library lookup on linux - #3 by Harald_Scheirich). but using (CMAKE_INSTALL_RPATH $Origin)

I am a bit confused.

Setting up rpath entries for external libraries is very dependent on the deployment setup. Packaging systems like Spack, Anaconda, or vcpkg already have ways to have packages find their dependencies. For custom builds, it’ll need to be figured out. The “easy way” is to just tell CMake to use the build rpath for the install rpath too with CMAKE_INSTALL_RPATH_USE_LINK_PATH. This only works if nothing will move after installation happens.

1 Like