Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the requirements for running a Rust compiled program on another Windows machine?

I'm totally new to Rust. I installed Rust on my Windows 10 machine. Created a simple helloworld program like this:

fn main() {
    print!("Hello world!");
}

And compiled it with rustc rust.rs. After that there are two files generated:

admin@myserver MINGW64 ~/Documents/rust_test
$ ls -latrh
total 1.6M
drwxr-xr-x 1 admin 197121    0 Sep  2 03:28 ..
-rw-r--r-- 1 admin 197121   45 Sep  4 00:26 rust.rs
-rwxr-xr-x 1 admin 197121 146K Sep  4 00:26 rust.exe
-rw-r--r-- 1 admin 197121 1.5M Sep  4 00:26 rust.pdb
drwxr-xr-x 1 admin 197121    0 Sep  4 00:26 .

I can successfully run rust.exe and get the proper result. However, when I copy rust.exe to another newly created Windows 2016 virtual machine and run it, I got this error:

enter image description here

My question is, what's the requirement to run a Rust compiled program on a machine that doesn't have Rust installed? Do I need to install the vc++ build tools on it too (just as I did on the development machine)?

like image 948
Just a learner Avatar asked Sep 03 '18 16:09

Just a learner


People also ask

Can rust be run in any machine?

The Rust compiler runs on, and compiles to, a great number of platforms, but is best supported on Linux, Mac, and Windows, on the x86 and x86-64 CPU architecture. There are official builds of the Rust compiler and standard library for these platforms and more.


2 Answers

You can also statically link the CRT by adding

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

to your .cargo/config. As pointed out in this Stack Overflow answer.

like image 60
Markus Klein Avatar answered Oct 04 '22 12:10

Markus Klein


You need to install the Microsoft Visual C++ Redistributable Package in the correct version.

The "140" in the file name in your error message indicates the version, which should be the Visual C++ Redistributable for Visual Studio 2015.


As a shortcut, here are the most common dowload links for other versions:

  • Microsoft Visual C++ Redistributable 2017 — 32-bit (x86), 64-bit (x64)
  • Microsoft Visual C++ Redistributable 2015 — 32-bit (x86), 64-bit (x64)
  • Microsoft Visual C++ Redistributable 2013 — 32-bit (x86), 64-bit (x64)
  • Microsoft Visual C++ Redistributable 2012 — 32-bit (x86), 64-bit (x64)
  • Microsoft Visual C++ Redistributable 2010 — 32-bit (x86), 64-bit (x64)
  • Microsoft Visual C++ Redistributable 2008 — 32-bit (x86), 64-bit (x64)
  • Microsoft Visual C++ Redistributable 2005 — 32-bit (x86), 64-bit (x64)
like image 31
Uwe Keim Avatar answered Oct 04 '22 12:10

Uwe Keim