{"id":"101dad83b6438b9d","repo":"rust-lang/cargo","slug":"library-cannot-set-the-crate-type-of-both-dy","errorCode":null,"errorMessage":"library `{}` cannot set the crate type of both `dylib` and `cdylib`","messagePattern":"library `(.+?)` cannot set the crate type of both `dylib` and `cdylib`","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":247,"sourceCode":"\n    let path = lib.path.as_ref().expect(\"previously normalized\");\n    let path = package_root.join(&path.0);\n\n    // Per the Macros 1.1 RFC:\n    //\n    // > Initially if a crate is compiled with the `proc-macro` crate type\n    // > (and possibly others) it will forbid exporting any items in the\n    // > crate other than those functions tagged #[proc_macro_derive] and\n    // > those functions must also be placed at the crate root.\n    //\n    // A plugin requires exporting plugin_registrar so a crate cannot be\n    // both at once.\n    let crate_types = match (lib.crate_types(), lib.proc_macro()) {\n        (Some(kinds), _)\n            if kinds.contains(&CrateType::Dylib.as_str().to_owned())\n                && kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>\n        {\n            anyhow::bail!(format!(\n                \"library `{}` cannot set the crate type of both `dylib` and `cdylib`\",\n                name_or_panic(lib)\n            ));\n        }\n        (Some(kinds), _) if kinds.contains(&\"proc-macro\".to_string()) => {\n            warnings.push(format!(\n                \"library `{}` should only specify `proc-macro = true` instead of setting `crate-type`\",\n                name_or_panic(lib)\n            ));\n            if kinds.len() > 1 {\n                anyhow::bail!(\"cannot mix `proc-macro` crate type with others\");\n            }\n            vec![CrateType::ProcMacro]\n        }\n        (Some(kinds), _) => kinds.iter().map(|s| s.into()).collect(),\n        (None, Some(true)) => vec![CrateType::ProcMacro],\n        (None, _) => vec![CrateType::Lib],\n    };","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/targets.rs#L229-L265","documentation":"Error \"library `{}` cannot set the crate type of both `dylib` and `cdylib`\" thrown in rust-lang/cargo.","triggerScenarios":"Thrown at src/workspace/parser/targets.rs:247 when the library encounters an invalid state.","commonSituations":"Occurs when a `[lib]` target lists both `dylib` and `cdylib` in `crate-type`. Choose one dynamic library crate type, as they are mutually exclusive.","solutions":["Pick only one of `dylib` or `cdylib` in the `[lib] crate-type` list.","Split into separate crates if both dynamic library flavors are needed."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}