Compilation fails linking if there are different versions of libusb
spcan opened this issue · comments
This issue comes from an attempted install of probe-run-rp
in which cargo would enter linking stage and then fail with various messages of undefined reference to libusb_xxxx
. The weird part is that it only affected this crate, other crates using rusb
compiled without even warnings.
This issue was solved after uninstalling the libraries libusb-dev
and libusb-0.1-4
and leaving installed only the library libusb-1.0-0-dev
.
I don't know if this is a bug or expected behaviour (after all, there were may versions of the same library).
It maybe some messed up in system. libusb1-sys try first to find system version of libusb by using pkg-config. If fail it's build libusb from source.
But this can be override with vendored
flags. And maybe other crate set this flag by default.
I had exactly the same problem and just found out what caused it. It happened when using the vendored feature and having libusb-0.1-4
installed on my system. In this case, the rlib for libusb was not build from the .a file inside the project, but from the old system libusb. Strange enough, this only happend on one of my 2 linux machines, the other one compiled rusb correctly.
I just tried to figure out why this is happening. I think the problem is cause by a name conflict. The libusb1-sys
crate creates a library named libusb.a
:
[libusb1-sys 0.5.0] running: "ar" "s" "/home/tiwalun/probe-run/target/debug/build/libusb1-sys-a45c14079015a9e8/out/libusb.a"
[libusb1-sys 0.5.0] exit status: 0
[libusb1-sys 0.5.0] cargo:rustc-link-lib=static=usb
[libusb1-sys 0.5.0] cargo:rustc-link-search=native=/home/tiwalun/probe-run/target/debug/build/libusb1-sys-a45c14079015a9e8/out
[libusb1-sys 0.5.0] cargo:version_number=1.0.24
But when libusb-0.1.4
is installed, pkg-config
shows the following flags for libusb:
$ pkg-config libusb --libs
-lusb
For libusb-1.0 the flags from pkg-config
are different:
$ pkg-config libusb-1.0 --libs
-lusb-1.0
I guess that the linker finds the system library from libusb-0.1.4
first, and this leads to the problem. But I don't know why that is the case.