-
Notifications
You must be signed in to change notification settings - Fork 154
Don't automatically link to libpcap #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hi, thanks for the PR! However, I don't understand the problem but the solution to be honest. Can I ask you to explain the original problem you are trying to solve? And how does your solution solve it? |
|
Consider a simple program that uses pcap: With pcap at f138c4b, its build.rs outputs: And when compiling the pcap crate, we see Looking at So, it's dynamically linking to If we apply the If we then remove the In my case, I want to statically link This produces: No dynamic libpcap, just as I wanted. |
pkg-config's default config will output `rustc-link-lib` when it finds a package. However, per this project's readme, linkage is the responsibility of the user, so it seems like merely probing for the version should not change any subsequent build config. Lines previously present in build.rs output that are now gone: ``` [pcap 2.3.0] cargo:rustc-link-search=native=/usr/lib/x86_64-linux-gnu [pcap 2.3.0] cargo:rustc-link-lib=pcap ``` Similarly, the `#[link(name = "pcap")]` in `raw` was making dependent binaries automatically link to libpcap.so.
f3f987c to
79304f4
Compare
|
Thanks for your very detailed explanation! I now understand the problem. Basically, it seems that if libpcap.so is present then it will dynamically link the library instead of the static one. I appreciate that this is a problem, but it is intentional that the build works as is if libpcap is present so I would rather not remove this "hands-off" dynamic linking if libpcap.so is present. At the same time, it is important that you can link statically even if libpcap is present. I did look at this in the past and I think it's doable without any changes to the code base. See my comment here: #195 (comment). Could you try the following flags in your project?: and let me know if it works for you as expected? |
|
Actually, I just noticed that you already have those flags - is it the case that even with those flags, the dynamic library is linked? |
|
It will statically link with rustc-link-lib=static=... in The behavior you describe is also a pretty direct contradiction of the readme:
If you want to maintain the automatic dynamic linking, it would be great to see the readme updated to reflect that, and ideally an env var I can set to turn it off. |
pkg-config's default config will output
rustc-link-libwhen it finds a package. However, per this project's readme, linkage is the responsibility of the user, so it seems like merely probing for the version should not change any subsequent build config.Lines previously present in build.rs output that are now gone:
Similarly, the
#[link(name = "pcap")]inrawwas making dependent binaries automatically link to libpcap.so.Dependent crates will need to either use a
#[link...snippet, or specify linkage via build.rs. That matches my understanding of the readme's linkage policy, and for what it's worth, as a user of the crate I'm fine with that. A downside with this approach is that it's possible to linklibpcaptwice since this crate doesn't specifylinkin its Cargo.toml, but presumably that's something you've already considered as a worthwhile tradeoff to avoid needing to have ever more environment variables to configure linkage.