Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-compilation to x86_64-unknown-linux-gnu fails on Mac OSX

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.

like image 794
rap-2-h Avatar asked Nov 04 '16 13:11

rap-2-h


1 Answers

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
like image 121
Jonas Avatar answered Oct 06 '22 03:10

Jonas