rust-pcap / pcap

Rust language pcap library
Apache License 2.0
610 stars 138 forks source link

Can't link to `libpcap.dylib` on macOS Big Sur #180

Closed dllu closed 2 years ago

dllu commented 3 years ago

I installed libpcap via brew. I am on macOS Big Sur Version 11.2.1.

> ls /usr/local/Cellar/libpcap/1.10.1/lib 
libpcap.1.10.1.dylib libpcap.A.dylib      libpcap.a            libpcap.dylib        pkgconfig

> export LIBPCAP_LIBDIR=/usr/local/Cellar/libpcap/1.10.1/lib/

> cargo build --release                                      
   Compiling pcap v0.8.1
error: failed to run custom build command for `pcap v0.8.1`

Caused by:
  process didn't exit successfully: `/Users/dllu/mything/target/release/build/pcap-8a0e77e7c7783176/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=LIBPCAP_LIBDIR
  cargo:rerun-if-env-changed=LIBPCAP_VER
  cargo:rustc-link-search=native=/usr/local/Cellar/libpcap/1.10.1/lib/

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: DlOpen { desc: "dlopen(libpcap.dylib, 2): image not found" }', /Users/dllu/.cargo/registry/src/github.com-1ecc6299db9ec823/pcap-0.8.1/build.rs:131:42
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

As you can see, even though I set the LIBPCAP_LIBDIR perfectly, it is unable to find libpcap.

However, this crate works perfectly on Linux.

Wojtek242 commented 3 years ago

Hi, sorry for the late reply, I was on holidays.

I've had a look and I think that's because build.rs loads libpcap during execution (to get the version number), but ignores LIBPCAP_LIBDIR which is only used for linking.

Can you please try the fix I put on the branch libdir-in-build-rs if this is still an issue for you.

Wojtek242 commented 2 years ago

This fix is now on master and in 0.9.0 which is available from crates.io. If it still doesn't work, please reopen the issue.