Cross-compile a Rust application from Linux to Windows

前端 未结 5 571
挽巷
挽巷 2020-12-12 15:02

Basically I\'m trying to compile the simplest code to Windows while I am developing on Linux.

fn main() {
    println!(\"Hello, and bye.\")
}
5条回答
  •  半阙折子戏
    2020-12-12 15:53

    Other answers, while technically correct, are more difficult than they need to be. There's no need to use rustc (in fact it's discouraged, just use cargo), you only need rustup and cargo.

    Add the target (you can also change this for whatever target you're cross compiling for):

    rustup target add x86_64-pc-windows-gnu
    rustup toolchain install stable-x86_64-pc-windows-gnu
    

    You can build your crate easily with:

    cargo build --target x86_64-pc-windows-gnu
    

    No need for messing around with ~/.cargo/config or anything else.

    EDIT: Just wanted to add that while you can use the above it can also sometimes be a headache. I wanted to add that the rust tools team also maintains a project called cross: https://github.com/rust-embedded/cross This might be another solution that you want to look into

提交回复
热议问题