{"id":"73cfd4530a928a89","repo":"rust-lang/rust","slug":"staticlibs-not-supported","errorCode":null,"errorMessage":"staticlibs not supported","messagePattern":"staticlibs not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_ssa/src/back/linker.rs","lineNumber":1940,"sourceCode":"    cmd: Command,\n    sess: &'a Session,\n}\n\nimpl<'a> Linker for LlbcLinker<'a> {\n    fn cmd(&mut self) -> &mut Command {\n        &mut self.cmd\n    }\n\n    fn set_output_kind(\n        &mut self,\n        _output_kind: LinkOutputKind,\n        _crate_type: CrateType,\n        _out_filename: &Path,\n    ) {\n    }\n\n    fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {\n        panic!(\"staticlibs not supported\")\n    }\n\n    fn link_staticlib_by_path(&mut self, path: &Path, _whole_archive: bool) {\n        self.link_or_cc_arg(path);\n    }\n\n    fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {\n        match strip {\n            Strip::None => {\n                self.link_arg(\"--debug\");\n            }\n            Strip::Debuginfo | Strip::Symbols => {}\n        }\n    }\n\n    fn optimize(&mut self) {\n        self.link_arg(match self.sess.opts.optimize {\n            OptLevel::No => \"-O0\",","sourceCodeStart":1922,"sourceCodeEnd":1958,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_ssa/src/back/linker.rs#L1922-L1958","documentation":"Thrown by link_staticlib_by_name on the LlbcLinker, which is the self-contained LLVM-bitcode linker used for -C linker-flavor=llbc (typically emscripten/wasm LTO linking). This linker can only consume bitcode/object files passed by path and has no mechanism to resolve a static library by name against a search path, so asking it to link a named staticlib is unsupported and panics.","triggerScenarios":"Invoked when the LLBC linker is in use and the build requests linking a static library by name (e.g. -l static=foo or #[link(name=\"foo\", kind=\"static\")]) rather than by explicit path. The LLBC flavor simply does not implement name-based staticlib resolution.","commonSituations":"Setting -C linker-flavor=llbc (or a target whose default flavor is llbc) while a dependency requests a named static library. Mixing native -l static dependencies into a wasm/emscripten LTO build. A build script emitting cargo:rustc-link-lib=static=... under an llbc toolchain.","solutions":["Link the static library by path instead of by name: pass the full .a path via cargo:rustc-link-lib=static:<path> or -C link-arg=<path.a>, which routes through link_staticlib_by_path (supported).","Avoid -C linker-flavor=llbc if the build genuinely needs named static libraries; use a linker flavor that supports library search.","If the dependency is optional, gate or remove the cargo:rustc-link-lib=static=... directive for llbc builds."],"exampleFix":"// build.rs before (named static lib, unsupported by llbc)\nprintln!(\"cargo:rustc-link-lib=static=foo\");\n// after (link by path so LlbcLinker::link_staticlib_by_path handles it)\nprintln!(\"cargo:rustc-link-lib=static:+whole-archive={}\",\n         out_dir.join(\"libfoo.a\").display());","handlingStrategy":"fallback","validationCode":"fn target_supports_staticlibs(target: &str) -> bool {\n    // wasm32-unknown-unknown and a few bare-metal targets reject `staticlib`.\n    !(target.starts_with(\"wasm32-\") && target.contains(\"unknown\"))\n        && !target.starts_with(\"bpfel-\")\n        && !target.starts_with(\"nvptx\")\n}\n\n// caller: if !target_supports_staticlibs(&target) { use_cdylib_instead()?; }","typeGuard":"fn target_allows_staticlib(target: &str) -> bool {\n    target_supports_staticlibs(target)\n}","tryCatchPattern":"let stderr = String::from_utf8_lossy(&output.stderr);\nif stderr.contains(\"staticlibs not supported\") {\n    // Fallback: switch crate-type from `staticlib` to `cdylib` for this target.\n    rebuild_with_crate_types(&[\"cdylib\"])?;\n}","preventionTips":["Do not request `crate-type = [\"staticlib\"]` for `wasm32-unknown-unknown`.","Conditionally compile crate types per target via `[lib] crate-type` overrides or `cfg`.","When integrating with C on wasm, prefer `cdylib` and load the `.wasm` artifact instead."],"tags":["llbc","linker-flavor","wasm","static-library","lto"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}