rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Document how to use bindgen with pkg-config or similar.

Open emilio opened this issue 8 years ago • 1 comments

It may be useful to see documentation on bindgen being integrated with it, or with stuff that requires altering the include path in bindgen in general.

It'd be a nice addition to the book I think.

emilio avatar Feb 04 '18 15:02 emilio

This seems to work, though it does feel weird that I have to do this.

    let library = pkg_config::probe_library("foobar")?;
    let bindings = bindgen::Builder::default()
        .clang_args(library.include_paths.iter().map(|path| format!("-I{}", path.to_string_lossy())))
        .header("src/wrapper.h")
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .expect("Unable to generate bindings");

WGH- avatar Feb 08 '22 23:02 WGH-