Skip to content

Instantly share code, notes, and snippets.

@yordanoweb
Last active January 13, 2025 19:56
Show Gist options
  • Save yordanoweb/808d0bb0f39b8434fcf6c4a8ad3e5c9a to your computer and use it in GitHub Desktop.
Save yordanoweb/808d0bb0f39b8434fcf6c4a8ad3e5c9a to your computer and use it in GitHub Desktop.
Rust static build

Rust static build

In the root of the Rust project, compile with this leading option:

RUSTFLAGS="-C target-feature=+crt-static" cargo build --target x86_64-unknown-linux-gnu

For a release compilation

RUSTFLAGS="-C target-feature=+crt-static" cargo build --target x86_64-unknown-linux-gnu --release

I tested the compilation in:

Operating System: Archcraft                       
          Kernel: Linux 6.0.10-arch2-1
    Architecture: x86-64
Firmware Version: 1007

The resulting executable worked in target system:

    Virtualization: vmware
  Operating System: Ubuntu 14.04.3 LTS
            Kernel: Linux 3.19.0-49-generic
      Architecture: x86_64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment