Search code examples
rustrust-cargohidapi

Can't build hidapi rust example


filip@filip-pc:~/Desktop/hidTest$ cargo build
   Compiling pkg-config v0.3.17
   Compiling libc v0.2.71
   Compiling cc v1.0.54
   Compiling hidapi v1.2.2
error: failed to run custom build command for `hidapi v1.2.2`

Caused by:
  process didn't exit successfully: `/home/filip/Desktop/hidTest/target/debug/build/hidapi-f1cb7b18f844a4a0/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Unable to find libusb-1.0: "`\"pkg-config\" \"--libs\" \"--cflags\" \"libusb-1.0\"` did not exit successfully: exit code: 1\n--- stderr\nPackage libusb-1.0 was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libusb-1.0.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'libusb-1.0\' found\n"', /home/filip/.cargo/registry/src/github.com-1ecc6299db9ec823/hidapi-1.2.2/build.rs:65:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I just try to run the example from docs https://docs.rs/hidapi/1.2.2/hidapi/

Have anybody encounter this error ?

I already try

cargo clean

and

cargo build

again


Solution

  • You must install libusb-1.0 on your system. You seem to be using Homebrew, so you also have to install it specifically via Homebrew, because that's where pkg-config is looking for it.

    It's possible that Homebrew doesn't offer this library under this exact name, or that the hidapi crate isn't compatible with macOS. Check the hidapi crate for details, as it's a crate-specific problem.