Open jerry73204 opened 4 years ago
In case this is helpful, I stumbled across what appears to be a workaround for the same issue in libz-sys: https://github.com/rust-lang/libz-sys/blob/6b12e9a37bae1a444aaa1a11248c5b0e555869b4/build.rs#L37-L43 (which seems relevant because libz-sys is the example that the Cargo docs use for exposing a native library)
The section in build.rs can possibly add the standard path
/usr/lib
(or/usr/lib/x86_64-linux-gnu
on Debian) to therustc-link-search
path. It will introduce an extra-L/usr/lib
flag to the linker. It is not desired because it overrides the search order of other more specific search paths.I encountered a scenario to import both
opencv
anddiesel
in my project. I install the OpenCV 4 in non-standard path (It's because Ubuntu ships the older OpenCV), and setPKG_CONFIG_PATH
to let thebuild.rs
inopencv
crate to append the non-standard search paths for me.In the mean time, the
pq-sys
required bydiesel
puts the standard search path to the linker as I pointed here. It causes the linker to search forlibopencv_*.so
in both standard and non-standard paths, and the build fails due to conflict.I see an obvious solution is the
pkg-config
feature. However,pq-sys
is not the direct dependency of my project but for the dependentdiesel
, making the patch a bit difficult. The build script itself should also avoid producing standard paths to the linker.