Search code examples
bazel

what's bazel dynamic library search path?


I used the ldd command to print out the binary build through bazel and the result is as follows.

libexternal_Scom_Ugoogle_Uprotobuf_Slibprotobuf.so => /apollo/bazel-bin/cyber/../_solib_k8/libexternal_Scom_Ugoogle_Uprotobuf_Slibprotobuf.so (0x00007f5900b1c000)
    libexternal_Scom_Ugoogle_Uprotobuf_Slibprotobuf_Ulite.so => /apollo/bazel-bin/cyber/../_solib_k8/libexternal_Scom_Ugoogle_Uprotobuf_Slibprotobuf_Ulite.so (0x00007f59009f7000)
    libexternal_Szlib_Slibzlib.so => /apollo/bazel-bin/cyber/../_solib_k8/libexternal_Szlib_Slibzlib.so (0x00007f59009d8000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f59007d0000)
    libPocoFoundation.so.71 => /opt/apollo/sysroot/lib/libPocoFoundation.so.71 (0x00007f59003a5000)
    libatomic.so.1 => /usr/lib/x86_64-linux-gnu/libatomic.so.1 (0x00007f590019d000)

My question is I found LD_LIBRARY_PATH path not have

/apollo/bazel-bin/cyber/../_solib_k8/

So how is this path added to find the dynamic library?


Solution

  • I finally found out that bazel doesn't change LD_LIBRARY_PATH, but if you want to add use it, it works too.

    bazel writes the path to binary, which implements this function by calling gcc -rpath, so that the dynamic library will be searched from rpath when linking. https://en.wikipedia.org/wiki/Rpath