{"record":{"id":"26dde2830d29878f","repo":"rust-lang/cargo","slug":"multiple-packages-link-to-native-library-but","errorCode":null,"errorMessage":"multiple packages link to native library `{}`, but a native library can be linked only once\n\n{}\nlinks to native library `{}`\n\n{}\nalso links to native library `{}`","messagePattern":"multiple packages link to native library `(.+?)`, but a native library can be linked only once\n\n(.+?)\nlinks to native library `(.+?)`\n\n(.+?)\nalso links to native library `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/links.rs","lineNumber":44,"sourceCode":"    units.sort_unstable();\n    for unit in units {\n        if !validated.insert(unit.pkg.package_id()) {\n            continue;\n        }\n        let Some(lib) = unit.pkg.manifest().links() else {\n            continue;\n        };\n        if let Some(&prev) = links.get(lib) {\n            let prev_path = resolve\n                .path_to_top(&prev)\n                .into_iter()\n                .map(|(p, d)| (p, d.and_then(|d| d.iter().next())));\n            let pkg = unit.pkg.package_id();\n            let path = resolve\n                .path_to_top(&pkg)\n                .into_iter()\n                .map(|(p, d)| (p, d.and_then(|d| d.iter().next())));\n            anyhow::bail!(\n                \"multiple packages link to native library `{}`, \\\n                 but a native library can be linked only once\\n\\\n                 \\n\\\n                 {}\\nlinks to native library `{}`\\n\\\n                 \\n\\\n                 {}\\nalso links to native library `{}`\",\n                lib,\n                describe_path(prev_path),\n                lib,\n                describe_path(path),\n                lib\n            )\n        }\n        links.insert(lib.to_string(), unit.pkg.package_id());\n    }\n    Ok(())\n}\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/compiler/links.rs#L26-L62","documentation":"Two packages in the dependency graph both declare `links = \"<lib>\"` for the same native library name. Cargo enforces that each native library is linked by exactly one package (to avoid duplicate symbols / `-l` flags), and bails showing the two dependency paths to the conflicting packages.","triggerScenarios":"Two crates in the resolved graph set identical `links = \"foo\"` in their manifests; a dependency was duplicated via different version requirements that both carry the same `links`.","commonSituations":"Vendoring a library that's also pulled transitively; forked crates that didn't change the `links` value; version conflicts where both 1.x and 2.x of a crate link the same native lib.","solutions":["Pick one source of the native linkage: remove or rename the `links` value on the duplicate, or exclude one version from the graph.","If two unrelated crates legitimately wrap the same system lib, deduplicate by having one depend on the other.","Use `cargo tree -i <pkg>` to find both paths and resolve the version conflict.","Patch the offending crate to use a unique `links` name when vendoring."],"exampleFix":"// before (Cargo.toml of crate A and crate B)\nlinks = \"sqlite3\"\n\n// after (crate B)\nlinks = \"sqlite3_b\"\n# or remove `links` from crate B and depend on crate A","handlingStrategy":"validation","validationCode":"fn unique_links_values(manifests: &[&Manifest]) -> bool {\n    let mut seen = std::collections::HashSet::new();\n    manifests.iter().filter_map(|m| m.links()).all(|l| seen.insert(l))\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["When vendoring, rename `links` to a unique value.","Run `cargo tree -d` to catch duplicate versions of linking crates before release.","Document the `links` contract for downstream wrappers."],"tags":["cargo","native-lib","links","dependency-graph","symbols"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}