Linker chaos with regular GCC stdenv and CMake packages

I’m struggling with an odd issue where a corpus of ROS (robot operating system) packages are appearing to build fine under Nix, but then a handful of dependency chains are ending up with dangling linker issues at runtime, for example:

ldd /nix/store/phrrhk85gcd6xv34j4sh34q75znk17g5-cpr_slam_utils/lib/cpr_slam_utils/cache_map
...
        libpcl_segmentation.so.1.11 => /nix/store/l1xvb5a27bnqav41h9kpjbk9ngx4v6yi-pcl-1.11.1/lib/libpcl_segmentation.so.1.11 (0x00007f87d08f4000)
        libpcl_surface.so.1.11 => /nix/store/l1xvb5a27bnqav41h9kpjbk9ngx4v6yi-pcl-1.11.1/lib/libpcl_surface.so.1.11 (0x00007f87cfb5d000)
        libqhull_r.so.8.0 => not found
...
        libqhull_r.so.8.0 => /nix/store/rkdhlrlnh1i7r0mi68cnxhpp39x83jiz-qhull-2020.2/lib/libqhull_r.so.8.0 (0x00007fdecebda000)

Basically, libpcl_surface is how qhull is becoming a dependency of cache_map, and for that library in isolation, the linker does fine:

$ ldd /nix/store/l1xvb5a27bnqav41h9kpjbk9ngx4v6yi-pcl-1.11.1/lib/libpcl_surface.so.1.11 | grep qhull
        libqhull_r.so.8.0 => /nix/store/rkdhlrlnh1i7r0mi68cnxhpp39x83jiz-qhull-2020.2/lib/libqhull_r.so.8.0 (0x00007f7007638000)

But when it tries to link libpcl_surface into other binaries, it’s missing this dependency and only finds it later on in the output. You’d think this might be fine, but the interpreter errors out at runtime:

$ /nix/store/phrrhk85gcd6xv34j4sh34q75znk17g5-cpr_slam_utils/lib/cpr_slam_utils/cache_map
/nix/store/phrrhk85gcd6xv34j4sh34q75znk17g5-cpr_slam_utils/lib/cpr_slam_utils/cache_map: error while loading shared libraries: libqhull_r.so.8.0: cannot open shared object file: No such file or directory

Unfortunately, this code isn’t public; I’m working on getting together a shareable MWE, but in the short term, I’d love if anyone had tips for probable causes with this kind of thing. I’m having a similar issue with libraries from the vtk package, and I feel like I’ve been paging through readelf/ldd/nix why-depends output, and struggling to make meaningful progress with any of it.

If it’s relevant, I’m not using the standard CMake builder in nixpkgs, and am instead rolling my own by wrapping a ROS build tool called colcon (which in turn calls cmake and make). However, the standard fixupPhase stuff is in place, and seems to otherwise mostly work fine. The only change I’ve otherwise made is adding the --as-needed linked flag, since the ROS build system has a habit of massively overlinking (but I tried doing a build of this stuff without --as-needed and the problem was the same).

Happy for any thoughts or pointers.

1 Like

This turned out to be an issue with the PCL package not properly propagating the dependencies of the libraries it generates. I’ve proposed a fix here:

1 Like