Could not find native static library, perhaps an -L flag is missing?

I'm coming back to a project which used to build with no problems a few Rust and OS versions ago (probably around Rust 1.75 or so and Alpine 3.19) but now gives this error when I try to build statically against libpcap:

error: could not find native static library pcap, perhaps an -L flag is missing?

The library is installed and exists as /usr/lib/libpcap.a

My build script contains println!("cargo:rustc-link-lib=static=pcap"); and I've tried the LIBPCAP_VER and LIBPCAP_LIBDIR env vars with no difference to result.

Running cargo through strace shows it seems to only look for the library in rustlib/:
[pid 20715] stat("/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libpcap.a", <unfinished ...>
[pid 20715] <... stat resumed>0x7f1f0d4e1f30) = -1 ENOENT (No such file or directory)

What am I doing wrong?

Use rustc-link-search to tell rustc where to search.

As a workaround may be symlink the library in /usr/lib/libpcap.a under /usr/lib/rustlib/x86_64-alpine-linux-musl/lib/?

What linker are you using now? For example mold doesn't lookup places like /usr/lib by default. You may need to specify all the directories it need to lookup.

Thanks, that got it. I can only assume that the defaults for something had changed somewhere!

I got the same problem with gcc and clang linkers but fortunately setting the rustc-link-search parameter in build.rs solved it.