4

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.

Lii
  • 11,553
  • 8
  • 64
  • 88
Thomas
  • 311
  • 2
  • 17
  • You need a statically build libgcc in order for `-static-libgcc` to do anything if I remember correctly. Are you sure your cross-compiler actually provides a static version of libgcc? I believe it should be named `libgcc_s.a` – rubenvb Aug 13 '19 at 10:00

0 Answers0