rust-pcap / pcap

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

Can it support Alpine? #239

Closed ZingerLittleBee closed 2 years ago

ZingerLittleBee commented 2 years ago

First of all, thanks for your contribution. I meet panic like below when pcap build in alpine

--- stdout
  cargo:rerun-if-env-changed=LIBPCAP_LIBDIR
  cargo:rerun-if-env-changed=LIBPCAP_VER

--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: DlOpen { desc: "Dynamic loading not supported" }', build.rs:141:52
Wojtek242 commented 2 years ago

Looks like dynamic linking is not supported. You will need to get a static libpcap.a library and instruct rustc from build.rs to link it statically. You will at least need the following in your build.rs:

println!("cargo:rustc-link-lib=static=pcap");

For more instructions on linking statically, see https://doc.rust-lang.org/cargo/reference/build-scripts.html

tomaszjonak commented 9 months ago

Note that provided solution will still fail if LIBPCAP_VER is unset.

tl;dr this env var short circuits rust-pcap build.rs get_pcap_lib_version function. If not set said function fails on either lack of shared pcap library or errors out on dlopen as described in initial issue.