How to add library to RPATH?

The original issue is this one. Whether it is resolved or not, I’m interested in the proper way of dealing with “local” runtime libraries. As mentioned in the above issue, the executable $out/bin/cb cannot find their runtime dependency libcbx11.so, which is physically present in the path $out/lib/libcbx11.so. I even added "-DCMAKE_INSTALL_RPATH=${placeholder "out"}/lib" in cmakeFlags, but it feels like it’s being stripped after the installation succeeded from the executable’s RUNPATH which is /nix/store/vaxgqbm6h3zvhpgk9xqqk97hqjp9gzvs-gcc-12.2.0-lib/lib:/nix/store/d7jh1dgmsz9h7x9kaalrv8lm00h8pcqn-gcc-12.2.0-libgcc/lib. Therefore, I would appreciate if someone would answer the following:

  • why is the library path removed from RUNPATH? It should be there, logically, since these libraries are in the folder $out/lib for a reason. That’s, like, really obvious they’re needed.
  • how can one prevent this from happening?

I also found this question, but playing with addAutoPatchelfSearchPath doesn’t help and it feels like a strange workaround around something obvious.

Thanks for your attention!

why is the library path removed from RUNPATH?

Probably because it’s soname isn’t listed in DT_NEEDED (cf. patchelf --print-needed .../bin/cb)

how can one prevent this from happening?

patchelf $out/bin/cb/ --add-needed libcbx11.so

How to add library to RPATH?

If that really were the goal, patchelf $out/bin/cb --append-rpath $out/lib. But you normally want --add-needed instead

1 Like

Thanks a lot for your reply!

While it feels like using patchelf is hacky, I got it working with the following:

postFixup = ''
  patchelf $out/bin/cb --add-rpath $out/lib
'';

I didn’t manage to get it working by --add-needed. Maybe this should happen prior to postFixup, I’m not sure.

And this library isn’t included in DT_NEEDED indeed.

preFixup seems to work, e.g. cudaPackages.cuda_nvrtc: force-load libnvrtc-builtins, because it was… · SomeoneSerge/nixpkgs@f55d2a1 · GitHub

While it feels like using patchelf is hacky

I think it would be nice to have a more declarative way to do this, but in principle the effect is going to be something like a patchelf invocation anyway?

1 Like

Indeed, if I do this during preFixup the libraries are added to RUNPATH. However, the executable itself fails with

./cb: ./cb: no version information available (required by ./cb)
fish: Job 1, './cb' terminated by signal SIGSEGV (Address boundary error)

Anyway, I don’t quite need this, I can drop it, as you rightfully said that whatever works is ok.

EDIT: this was probably off-topic