Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCRUNTIME140.dll missing on target machine #100874

Closed
juie887 opened this issue Aug 22, 2022 · 12 comments
Closed

VCRUNTIME140.dll missing on target machine #100874

juie887 opened this issue Aug 22, 2022 · 12 comments
Labels
O-windows Operating system: Windows

Comments

@juie887
Copy link

juie887 commented Aug 22, 2022

Whenever Itry to run a program compiled in rust on a target machine, it gives me an error code saying VCRUNTIME140.dll missing. How can I avoid this without any extra installations on the target machine

@CryZe
Copy link
Contributor

CryZe commented Aug 22, 2022

@juie887
Copy link
Author

juie887 commented Aug 22, 2022 via email

@ChrisDenton
Copy link
Member

If you just want to static link vcruntime (and not the whole CRT), here's a crate for that. It's used from a build script (build.rs).

Though if you do want to statically link everything then only follow the instructions at the bottom:

In the same directory as your Cargo.toml, create a folder called .cargo. In that folder create the file config.toml and add the following:

[target.'cfg(all(windows, target_env = "msvc"))']
rustflags = ["-C", "target-feature=+crt-static"]

@juie887
Copy link
Author

juie887 commented Aug 22, 2022

Hello Chris,
I just tried this and I get an error code when building error: linking with link.exe failed: exit code: 1120

How do I fix this please

@ChrisDenton
Copy link
Member

It's a bit hard to diagnose with just that error code but you could try doing cargo clean before rebuilding. Btw here's two "hello world" example projects:

@juie887
Copy link
Author

juie887 commented Aug 22, 2022 via email

@ChrisDenton
Copy link
Member

Do either of the examples work for you?

@juie887
Copy link
Author

juie887 commented Aug 23, 2022

Hi Chris,

I used the code below in my .cargo/config and when I tried installing on target pc I didn't get any runtime error but my program ceased to install. Now I'm even more confused

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

@ChrisDenton
Copy link
Member

It is very hard to diagnose such issues remotely and with limited information. My best guess is that a dependency of your application is set up for dynamic linking (it would explain the errors you encountered earlier). But that is just a guess. You may need to use a debugger to find out why it isn't working.

One other option is to give up trying to statically link and redistribute just the dll in the same folder as your application. You can find the redistributable dll using the "Developer Powershell" that should be in your start menu.

Type:

Join-Path $env:VCToolsRedistDir x64\Microsoft.VC143.CRT\vcruntime140.dll

This will give the path to vcruntime140.dll. You may need to change Microsoft.VC143.CRT to Microsoft.VC142.CRT depending on your version.

@Dylan-DPC
Copy link
Member

Closing this as it is a user-help issue

@rubo
Copy link

rubo commented May 11, 2023

Similar issue here. On a freshly installed Windows Server 2022, our library fails to find vcruntime140.dll while there is another one -- vcruntime140_clr0040.dll. For testing purposes, I copied that file with the vcruntime140.dll name, and that fixed the issue. Is this something that can be improved in the Rust toolchain or we're sentenced to install the Visual C++ Redistributable in such cases?

@Dylan-DPC
Copy link
Member

Sorry i meant to close this :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

6 participants