rust-lang/cargo · error · anyhow::Error
library `{}` cannot set the crate type of both `dylib` and `
Error message
library `{}` cannot set the crate type of both `dylib` and `cdylib` What it means
Error "library `{}` cannot set the crate type of both `dylib` and `cdylib`" thrown in rust-lang/cargo.
Source
Thrown at src/workspace/parser/targets.rs:247
let path = lib.path.as_ref().expect("previously normalized");
let path = package_root.join(&path.0);
// Per the Macros 1.1 RFC:
//
// > Initially if a crate is compiled with the `proc-macro` crate type
// > (and possibly others) it will forbid exporting any items in the
// > crate other than those functions tagged #[proc_macro_derive] and
// > those functions must also be placed at the crate root.
//
// A plugin requires exporting plugin_registrar so a crate cannot be
// both at once.
let crate_types = match (lib.crate_types(), lib.proc_macro()) {
(Some(kinds), _)
if kinds.contains(&CrateType::Dylib.as_str().to_owned())
&& kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>
{
anyhow::bail!(format!(
"library `{}` cannot set the crate type of both `dylib` and `cdylib`",
name_or_panic(lib)
));
}
(Some(kinds), _) if kinds.contains(&"proc-macro".to_string()) => {
warnings.push(format!(
"library `{}` should only specify `proc-macro = true` instead of setting `crate-type`",
name_or_panic(lib)
));
if kinds.len() > 1 {
anyhow::bail!("cannot mix `proc-macro` crate type with others");
}
vec![CrateType::ProcMacro]
}
(Some(kinds), _) => kinds.iter().map(|s| s.into()).collect(),
(None, Some(true)) => vec![CrateType::ProcMacro],
(None, _) => vec![CrateType::Lib],
};View on GitHub (pinned to 0e07a15537)
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.
When it happens
Trigger: Thrown at src/workspace/parser/targets.rs:247 when the library encounters an invalid state.
Common situations: Occurs when a `[lib]` target lists both `dylib` and `cdylib` in `crate-type`. Choose one dynamic library crate type, as they are mutually exclusive.
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/101dad83b6438b9d.json.
Report an issue: GitHub.