8 releases

Uses old Rust 2015

0.2.3 Jul 24, 2016
0.2.2 Jan 27, 2016
0.2.1 Nov 5, 2015
0.2.0 Oct 18, 2015
0.0.2 Mar 29, 2015

#188 in Hardware support

Download history 531/week @ 2021-01-16 584/week @ 2021-01-23 534/week @ 2021-01-30 557/week @ 2021-02-06 547/week @ 2021-02-13 499/week @ 2021-02-20 649/week @ 2021-02-27 433/week @ 2021-03-06 444/week @ 2021-03-13 627/week @ 2021-03-20 454/week @ 2021-03-27 577/week @ 2021-04-03 624/week @ 2021-04-10 471/week @ 2021-04-17 361/week @ 2021-04-24 439/week @ 2021-05-01

2,255 downloads per month
Used in 24 crates (2 directly)

MIT license

374 lines

Libusb Rust Bindings

The libusb-sys crate provides declarations and linkage for the libusb C library. Following the *-sys package conventions, the libusb-sys crate does not define higher-level abstractions over the native libusb library functions.


In order to use the libusb-sys crate, you must have the libusb library installed where it can be found by pkg-config.

All systems supported by libusb are also supported by the libusb-sys crate. It's been tested on Linux, OS X, and Windows.


To link to a cross-compiled version of the native libusb library, it's necessary to set several environment variables to configure pkg-config to work with a cross-compiler's sysroot. Autotools Mythbuster has a good explanation of supporting cross-compilation with pkg-config.

However, Rust's pkg-config build helper doesn't support calling a $CHOST-prefixed pkg-config. It will always call pkg-config without a prefix. To cross-compile libusb-sys with the pkg-config build helper, one must define the environment variables PKG_CONFIG_DIR, PKG_CONFIG_LIBDIR, and PKG_CONFIG_SYSROOT_DIR for the default pkg-config. It's also necessary to set PKG_CONFIG_ALLOW_CROSS to tell Rust's pkg-config helper that it's okay to proceed with a cross-compile.

To adapt the pkg-config wrapper in the Autotools Mythbuster guide so that it works with Rust, one will end up with a script similar to the following:



export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig

cargo build


Add libusb-sys as a dependency in Cargo.toml:

libusb-sys = "0.2"

Import the libusb_sys crate and use the functions as they're defined in the native libusb library. See the libusb 1.0 API documention for more usage information.

extern crate libusb_sys as ffi;

fn main() {
  let version = unsafe { ffi::libusb_get_version() };

  println!("libusb v{}.{}.{}.{}", version.major, version.minor, version.micro, version.nano);

Finding Help

Since libusb-sys is no more than a wrapper around the native libusb library, the best source for help is the information already available for libusb:


Copyright © 2015 David Cuddeback

Distributed under the MIT License.