diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index fad6f4394418a..ad973a5cb7870 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -811,10 +811,22 @@ impl<'a> Linker for MsvcLinker<'a> { self.cmd.arg(format!("{}{}", name, if verbatim { "" } else { ".lib" })); } - fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) { + fn link_staticlib_by_name( + &mut self, + name: &str, + verbatim: bool, + whole_archive: bool, + search_paths: &SearchPaths, + ) { + // Static libraries built by MSVC are usually called foo.lib. + // However, under MinGW and build systems such as Meson, they are + // called libfoo.a let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" }; - let suffix = if verbatim { "" } else { ".lib" }; - self.cmd.arg(format!("{prefix}{name}{suffix}")); + let search_paths = search_paths.get(self.sess); + let path = find_native_static_library(name, verbatim, search_paths, self.sess); + let mut arg = OsString::from(prefix); + arg.push(path); + self.cmd.arg(arg); } fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {