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

renaming of the library `C` was specified, however this crate contains no `#[link(...)]` attributes referencing this library

Open flevi29 opened this issue 3 years ago • 2 comments

Input C/C++ Header

I have no idea what causes the issue, and so I can't narrow it down, and also I'm not even sure if it's related to the header file https://github.com/NordicID/nur_sdk/blob/master/native/include/NurAPI.h

Bindgen Invocation

    bindgen::Builder::default()
        // blacklist a bunch of types and functions that hopefully will not be utilized
        // https://github.com/rust-lang/rust-bindgen/issues/1556#issuecomment-658317813
        .blocklist_type("LPMONITORINFOEXA?W?")
        // ...
        .blocklist_function("__C_specific_handler")
        // The input header we would like to generate
        // bindings for.
        .header("wrapper.h")
        // Tell cargo to invalidate the built crate whenever any of the
        // included header files changed.
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        // Finish the builder and generate the bindings.
        .generate()
        // Unwrap the Result and panic on failure.
        .expect("Unable to generate bindings");

Actual Results

error: renaming of the library `C` was specified, however this crate contains no `#[link(...)]` attributes referencing this library

Expected Results

I expect it to successfully build.

I suspect my problem is probably related to

    let root_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    println!("cargo:rustc-link-lib={}", Path::new(&root_dir)
        .join("NUR-lib")
        .display());

    // Tell cargo to invalidate the built crate whenever the wrapper changes
    println!("cargo:rerun-if-changed=wrapper.h");

NUR-lib contains x86 and x64 from https://github.com/NordicID/nur_sdk/tree/master/native/windows

I cannot determine what causes the error though or where to even start looking for a fix, I don't understand the implications of this error message, nor have I found another issue related to it other than this.

flevi29 avatar Mar 27 '22 10:03 flevi29

Yeah this seems unlikely to be related to bindgen, bindgen intentionally doesn't mess with anything compiler-related, just generates code. That said, maybe the CargoCallbacks are causing trouble? That'd be a bit surprising but... Does removing that help?

If not, can you post some concrete steps to reproduce? Something like:

  1. clone this repo
  2. cargo build
  3. ...

Or so?

emilio avatar Mar 27 '22 15:03 emilio

I commented the line

// .parse_callbacks(Box::new(bindgen::CargoCallbacks))

same error.

... can you post some concrete steps to reproduce?

Sure!

  1. clone this repo
  2. cargo build
  3. should err

flevi29 avatar Mar 27 '22 17:03 flevi29

I cloned the repo and tried building it. The linking error is no longer present. There's an error related to duplicated constants but it seems unrelated to this. Feel free to reopen.

pvdrz avatar Nov 23 '22 15:11 pvdrz