From bfde33f2fb00864302d034e91cd40f17d43ce961 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 16 Jan 2018 07:27:04 +0200 Subject: [PATCH 1/2] Add "-lmsvcrt" twice to get rustc to build with the latest mingw64 --- src/librustc_back/target/windows_base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_back/target/windows_base.rs b/src/librustc_back/target/windows_base.rs index e6aa745d54e9d..7a901dc913f94 100644 --- a/src/librustc_back/target/windows_base.rs +++ b/src/librustc_back/target/windows_base.rs @@ -59,6 +59,7 @@ pub fn opts() -> TargetOptions { "-lmingw32".to_string(), "-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc "-lmsvcrt".to_string(), + "-lmsvcrt".to_string(), // mingw is insane...? "-luser32".to_string(), "-lkernel32".to_string(), ]); From 16063416979e1f8643375e62e331b019a3ac8d4c Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Wed, 17 Jan 2018 01:18:04 +0200 Subject: [PATCH 2/2] Document the mingw -lmsvcrt hack better --- src/librustc_back/target/windows_base.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc_back/target/windows_base.rs b/src/librustc_back/target/windows_base.rs index 7a901dc913f94..cc40b8b052983 100644 --- a/src/librustc_back/target/windows_base.rs +++ b/src/librustc_back/target/windows_base.rs @@ -59,7 +59,15 @@ pub fn opts() -> TargetOptions { "-lmingw32".to_string(), "-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc "-lmsvcrt".to_string(), - "-lmsvcrt".to_string(), // mingw is insane...? + // mingw's msvcrt is a weird hybrid import library and static library. + // And it seems that the linker fails to use import symbols from msvcrt + // that are required from functions in msvcrt in certain cases. For example + // `_fmode` that is used by an implementation of `__p__fmode` in x86_64. + // Listing the library twice seems to fix that, and seems to also be done + // by mingw's gcc (Though not sure if it's done on purpose, or by mistake). + // + // See https://github.com/rust-lang/rust/pull/47483 + "-lmsvcrt".to_string(), "-luser32".to_string(), "-lkernel32".to_string(), ]);