Skip to content

Can't statically link MSVC runtime #290

Closed
@johnterickson

Description

Looks like it's hardcoded to dynamically link to the runtime. If someone points me in the right direction, I can send a PR to make a configurable, but I'm not sure where to start. I can confirm that changing it from msvcrt to libcmt makes a statically linked binary.

C:\src\libc>git diff
diff --git a/src/windows.rs b/src/windows.rs
index 21b6e13..3e20aad 100644
--- a/src/windows.rs
+++ b/src/windows.rs
@@ -99,7 +99,7 @@ pub const S_IWRITE: ::c_int = 128;
 pub const S_IREAD: ::c_int = 256;

 #[cfg(target_env = "msvc")] // " if " -- appease style checker
-#[link(name = "msvcrt")]
+#[link(name = "libcmt")]
 extern {}

 extern {

Here's the output of dumpbin for libcmt:


Microsoft (R) COFF/PE Dumper Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file c:\src\RustDrop\target\debug\vsts_drop.exe

File Type: EXECUTABLE IMAGE

  Image has the following dependencies:

    ADVAPI32.dll
    KERNEL32.dll
    USER32.dll
    WS2_32.dll
    SHELL32.dll

and for msvcrt:


Dump of file c:\src\RustDrop\target\debug\vsts_drop.exe

File Type: EXECUTABLE IMAGE

  Image has the following dependencies:

    ADVAPI32.dll
    KERNEL32.dll
    SHELL32.dll
    USER32.dll
    WS2_32.dll
    VCRUNTIME140.dll
    api-ms-win-crt-math-l1-1-0.dll
    api-ms-win-crt-string-l1-1-0.dll
    api-ms-win-crt-time-l1-1-0.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-environment-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-convert-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-utility-l1-1-0.dll
    api-ms-win-crt-filesystem-l1-1-0.dll
    api-ms-win-crt-conio-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll

Relevant thread: https://users.rust-lang.org/t/standalone-32bit-windows-app-using-msvc/3103

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions