{"record":{"id":"93534b855b834bc8","repo":"rust-lang/cargo","slug":"no-library-targets-found-in-package","errorCode":null,"errorMessage":"no library targets found in package `{}`","messagePattern":"no library targets found in package `(.+?)`","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/unit_generator.rs","lineNumber":452,"sourceCode":"                            let types = target.rustc_crate_types();\n                            let types_str: Vec<&str> = types.iter().map(|t| t.as_str()).collect();\n                            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                };","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/cargo_compile/unit_generator.rs#L434-L470","documentation":"Thrown by unit_generator when LibRule::True requires a library target but none of the selected packages expose one, and exactly one package is in scope (singular message form). This happens when the user asks cargo to build a library (e.g. `cargo build --lib`) for a package that has no [lib] target.","triggerScenarios":"Running `cargo build --lib` (or `--tests`/doc which need a lib) on a package whose Cargo.toml defines only [[bin]] targets; a binary-only crate being asked for its library.","commonSituations":"Binary-only application crates mistakenly built with --lib; crates whose [lib] was removed; tooling/IDE that defaults to --lib.","solutions":["Drop the --lib flag if you actually want the binary: `cargo build`.","Add a [lib] section to Cargo.toml if the crate should expose a library.","Point the build at the correct package that does have a lib: `-p <lib-pkg>`."],"exampleFix":"# before\ncargo build --lib\n# after (binary-only crate)\ncargo build --bin myapp","handlingStrategy":"validation","validationCode":"// Check the package has a [lib] target before --lib builds.\n// cargo metadata -> packages[].targets[].kind contains \"lib\" / \"rlib\" etc.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't pass --lib to binary-only crates.","Add a [lib] section when a library target is genuinely needed.","Select the correct package with -p when running library intents."],"tags":["cargo-compile","target-selection","library","manifest"],"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"}