Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

compilation - 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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...