rustrust-bindgen

Seeing bzlib.h not found when trying the Bindgen tutorial


I know there is a similar post to this but I followed it and I'm still seeing the issue so I thought I'd ask again sorry. I downloaded the bbindgen-tutorial-bzip2-sys and tried to run it but I get the following error

  wrapper.h:1:10: fatal error: 'bzlib.h' file not found
  wrapper.h:1:10: fatal error: 'bzlib.h' file not found, err: true

The other user suggested downgrading the Bindgen version in the .toml and I tried that and I still see the issue, also I verified that bzip2 is installed.

Is there a known clang version that works with Bindgen?

Thanks

-------------------------------------------------------Update------------------------------------------------------------------

So I installed the dev bzip files and verified that the library was in a folder that ld looked at by adding the path to LD_LIBRARY_PATH and then updating with ldconfig. I am now able to compile when I run CARGO BUILD,

fred@fred-MS-7B06:~/rust_projects/bindgen-tutorial-bzip2-sys-master$ cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s

however now when I try to run the program with CARGO TEST, as per the tutorial

https://rust-lang.github.io/rust-bindgen/print.html#include-the-generated-bindings-in-srclibrs

I now get the following error:

  = note: /bin/ld: cannot find -lbz2
          collect2: error: ld returned 1 exit status

I found a post that appeared to have the same issue:

https://dev.to/rrampage/cargo-refused-to-build-my-project---a-rust-debugging-story-25e9

And they fixed it by adding a config.toml file and specified the linker, I tried this and still got the same error. Any ideas as to what I can check I'm a little stuck on this one.

Also I checked the bzip2 dev file that I downloaded from the website:

https://www.sourceware.org/bzip2/

I noticed that there is no file called bz2 but there is a libbz2.def and a libbz2.dsp file, is it possible my ld is incorrectly removing the "lib" from the name?


Solution

  • As noted by @Jmb in the comments, I needed to install libbz2-dev:

    sudo apt install libbz2-dev
    

    Since this was a fairly new WSL instance of Ubuntu, I also needed libclang-dev:

    sudo apt install libclang-dev