{"id":"14ae698d639d0108","repo":"rust-lang/cargo","slug":"no-library-targets-found-in-packages","errorCode":null,"errorMessage":"no library targets found in packages: {}","messagePattern":"no library targets found in packages: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/unit_generator.rs","lineNumber":454,"sourceCode":"                            self.ws.gctx().shell().warn(format!(\n                                \"doc tests are not supported for crate type(s) `{}` in package `{}`\",\n                                types_str.join(\", \"),\n                                pkg.name()\n                            ))?;\n                        } else {\n                            libs.push(proposal)\n                        }\n                    }\n                    if !all_targets && libs.is_empty() && *lib == LibRule::True {\n                        let names = self\n                            .packages\n                            .iter()\n                            .map(|pkg| pkg.name())\n                            .collect::<Vec<_>>();\n                        if names.len() == 1 {\n                            anyhow::bail!(\"no library targets found in package `{}`\", names[0]);\n                        } else {\n                            anyhow::bail!(\n                                \"no library targets found in packages: {}\",\n                                names.join(\", \")\n                            );\n                        }\n                    }\n                    proposals.extend(libs);\n                }\n\n                let default_mode = to_compile_mode(self.intent);\n\n                // If `--tests` was specified, add all targets that would be\n                // generated by `cargo test`.\n                let test_filter = match tests {\n                    FilterRule::All => Target::tested,\n                    FilterRule::Just(_) => Target::is_test,\n                };\n                let test_mode = match self.intent {\n                    UserIntent::Build => CompileMode::Test,","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_compile/unit_generator.rs#L436-L472","documentation":"Same condition as error 89 but the multi-package branch (src/ops/cargo_compile/unit_generator.rs:454-457): multiple selected packages collectively lack any library target while LibRule::True is required. The names of all offending packages are joined.","triggerScenarios":"`cargo build --lib --workspace` (or -p across several crates) where none of the selected packages expose a [lib]. libs stays empty across all packages and LibRule::True holds.","commonSituations":"A workspace of binary-only crates where `--lib` was passed by mistake. Selecting several app crates expecting a shared lib that was moved or deleted.","solutions":["Inspect the listed package names; whichever should be a library needs a [lib] (src/lib.rs).","Remove --lib and target binaries/tests explicitly.","Narrow -p to the single package that actually has a lib."],"exampleFix":"# before\ncargo build --lib -p app-a -p app-b   # neither has a [lib]\n\n# after\ncargo build --lib -p shared-core      # the crate that actually has a lib","handlingStrategy":"validation","validationCode":"// For a multi-package --lib selection, ensure at least one member has a lib.\nfn any_lib_among(ws: &Workspace, names: &[String]) -> bool {\n    ws.members()\n        .filter(|m| names.iter().any(|n| n == m.name().as_str()))\n        .any(|m| m.targets().iter().any(|t| t.is_lib()))\n}","typeGuard":"fn selection_has_lib(pkgs: &[&cargo::core::Package]) -> bool {\n    pkgs.iter().flat_map(|p| p.targets()).any(|t| t.is_lib())\n}","tryCatchPattern":"if let Err(e) = ops::compile(ws, &opts) {\n    if e.to_string().contains(\"no library targets found in packages\") {\n        eprintln!(\"none of the selected packages has a [lib]; drop --lib or pick a lib crate\");\n    }\n    return Err(e);\n}","preventionTips":["For --workspace --lib, ensure at least one crate exposes a library.","Narrow -p to the crate that owns the lib."],"tags":["cargo","library","workspace","manifest","target-selection"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}