Closed
Description
Given static libraries, having duplicate -lfoo
is more likely to result in an error than not. Having multiple #[link]
blocks with kind="static"
specified or inferred in any way will cause the linking to fail. Consider for example this:
extern "C" {
#![link(name="zstd", kind="static")]
fn ZSTD_freeCCtx();
}
extern "C" {
#![link(name="zstd", kind="static")]
fn ZSTD_createCCtx();
}
fn main() {
unsafe {
ZSTD_createCCtx();
ZSTD_freeCCtx();
}
}
will pass to the linker
"-Wl,--whole-archive" "-lzstd" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-lzstd" "-Wl,--no-whole-archive"
which will fail due to duplicate symbols. This is somewhat surprising because rustc
will avoid passing through to the linker the -lfoo
from -l static=foo
if there’s a #[link]
attribute in the crate.