21

I tried to compile one of my Rust projects to the x86_64-unknown-linux-gnu target:

$ cargo build --target=x86_64-unknown-linux-gnu
 Compiling deployer v0.1.0 (file:///Users/raphael/web/deployer)
  error: linking with `cc` failed: exit code: 1
  |
  = note: "cc"
  = note: clang: warning: argument unused during compilation: '-pie'
ld: unknown option: --as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't know what to do with such a message. What should I do to make it work?

Here is my Cargo.toml file:

[package]
name = "deployer"
version = "0.1.0"
authors = ["..."]

[dependencies]
clap = "2.14.0"
time = "0.1.35"
slack-hook = "0.2"

Cargo version:

cargo 0.13.0-nightly (109cb7c 2016-08-19)

Rust version:

rustc 1.12.0 (3191fbae9 2016-09-23)

I tried to update everything with rustup, but I still get the same problem.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
  • FWIW, it's usually easier to [just build a native Linux version](https://github.com/japaric/rust-cross#i-want-to-build-binaries-for-linux-mac-and-windows-how-do-i-cross-compile-from-linux-to-mac), avoiding cross-compilation. – Shepmaster Nov 06 '16 at 03:57
  • That's what I done. – rap-2-h Nov 07 '16 at 08:45

1 Answers1

15

Inspired from cross-compile-rust-from-mac-to-linux, I typically install these dependencies to cross compile rust from Mac OS to Linux (e.g. for Docker containers):

rustup target add x86_64-unknown-linux-gnu

# Install a pre-built cross compiler
brew tap SergioBenitez/osxct
brew install x86_64-unknown-linux-gnu

And finally I can cross compile to Linux on Mac OS with:

CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc \
cargo build --target=x86_64-unknown-linux-gnu
Jonas
  • 121,568
  • 97
  • 310
  • 388