{"record":{"id":"b0da7054d6d14665","repo":"rust-lang/cargo","slug":"several-matching-instances-of-target-cfg-li","errorCode":null,"errorMessage":"several matching instances of `target.'cfg(..)'.linker` in configurations\nfirst match `{}` located in {}\nsecond match `{}` located in {}","messagePattern":"several matching instances of `target\\.'cfg\\(\\.\\.\\)'\\.linker` in configurations\nfirst match `(.+?)` located in (.+?)\nsecond match `(.+?)` located in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/compilation.rs","lineNumber":591,"sourceCode":"\n    // With `target-applies-to-host = true`,\n    // host artifacts must fall through to pick up from [target]\n    // since this is the stable behavior\n    if kind.is_host() && !bcx.gctx.target_applies_to_host()? {\n        return Ok(None);\n    }\n\n    // Try target.'cfg(...)'.linker.\n    let target_cfg = bcx.target_data.info(kind).cfg();\n    let mut cfgs = bcx\n        .gctx\n        .target_cfgs()?\n        .iter()\n        .filter_map(|(key, cfg)| cfg.linker.as_ref().map(|linker| (key, linker)))\n        .filter(|(key, _linker)| CfgExpr::matches_key(key, target_cfg));\n    let matching_linker = cfgs.next();\n    if let Some((key, linker)) = cfgs.next() {\n        anyhow::bail!(\n            \"several matching instances of `target.'cfg(..)'.linker` in configurations\\n\\\n             first match `{}` located in {}\\n\\\n             second match `{}` located in {}\",\n            matching_linker.unwrap().0,\n            matching_linker.unwrap().1.definition,\n            key,\n            linker.definition\n        );\n    }\n    Ok(matching_linker.map(|(_k, linker)| linker.val.clone().resolve_program(bcx.gctx)))\n}\n\nfn explicit_host_kind(host: &str) -> CompileKind {\n    let target = CompileTarget::new(host, false).expect(\"must be a host tuple\");\n    CompileKind::Target(target)\n}\n","sourceCodeStart":573,"sourceCodeEnd":608,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/compiler/compilation.rs#L573-L608","documentation":"Symmetric to error 26 but for `linker`: two or more `[target.'cfg(...)'.linker]` entries match the current target's cfg set, so the linker is ambiguous and Cargo aborts rather than guess.","triggerScenarios":"Layered config (global `~/.cargo/config.toml` + project `.cargo/config.toml` + `CARGO_TARGET_*_LINKER`) where cfg-based linker entries both match; refactoring cfg predicates into overlapping ranges.","commonSituations":"Teams share a global config that sets a linker, then a project config also sets one for a broader cfg; CI sets `CARGO_TARGET_CFG_GNU_LINKER` while config file also covers it.","solutions":["Consolidate to one config source or use exact-triple `target.<triple>.linker` keys.","Disambiguate cfg predicates so only one matches the target.","Remove the duplicate entry referenced by `first match`/`second match`.","Audit all config layers with `cargo config get` to see merged sources."],"exampleFix":"// before\n# ~/.cargo/config.toml\n[target.'cfg(target_env = \"gnu\")'.linker]\nlinker = \"gcc\"\n# ./.cargo/config.toml\n[target.'cfg(target_os = \"linux\")'.linker]\nlinker = \"clang\"\n\n// after: keep only one\n[target.x86_64-unknown-linux-gnu.linker]\nlinker = \"clang\"","handlingStrategy":"validation","validationCode":"fn count_matching_linker_cfgs(target_cfg: &[String], cfgs: &[(String, Linker)]) -> usize {\n    cfgs.iter().filter(|(k, _)| cfg_matches(k, target_cfg)).count()\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Use exact-triple `target.<triple>.linker` keys to avoid cfg overlap.","Audit env vars `CARGO_TARGET_*_LINKER` against file-based linker config.","Run `cargo config get target` to confirm a single match."],"tags":["cargo","config","linker","target-cfg","ambiguous"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}