rust-lang/git2-rs

`libgit2` found for linking, but not loading (i.e. missing `rpath`).

Opened this issue · 0 comments

I have a build script using git2, which builds fine, but when it is executed, fails with:

/target/debug/build/built2-42d7a0628db36d4d/build-script-build: error while loading shared libraries: libgit2.so.1.9: cannot open shared object file: No such file or directory

The problem is libgit2.so.1.9 is found in /home/linuxbrew/.linuxbrew/Cellar/libgit2/1.9.0/lib/libgit2.so.1.9 (via Homebrew-installed pkg-config), but when executing cannot find it since it is not in the load path.

Ideally, the libgit2-sys build script should add that directory as rpath, but cargo has no way of forwarding this to a dependent binary (yet) using e.g. cargo:rustc-link-arg.

For normal binaries, you can hack the rpath into build.rs, but there is no way to set it for the build.rs itself other than setting RUSTFLAGS manually.

Maybe there is a way to detect when a package is found with pkg-config but cannot actually be loaded (e.g. using ldconfig -p) and fall back to using the vendored version in that case.