Thomas
Thomas

Reputation: 371

How do I link libgcc statically in rust

I am trying to compile a Rust program with statically linked libgcc.

The program is meant to run in initramfs in a restricted environment and is compiled for different platforms (arm, x86_64).

Currently my only solution is to compile against musl which produces a statically linked binary.

Unfortunately this adds a bit of complexity to the build process - I have not found a way to cross-compile for arm-musl on x86 and I have extra installation requirements (musl-gcc).

I have tried to add this:

[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-args=-static-libgcc"]

...to .cargo/config, but as far as I understand +crt-static only works on Windows, and -static-libgcc showed no effect either.

Upvotes: 5

Views: 2003

Answers (0)

Related Questions