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

1

27

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.

Naoise answered 4/11, 2016 at 13:44 Comment(2)
FWIW, it's usually easier to just build a native Linux version, avoiding cross-compilation.Nemathelminth
That's what I done.Naoise
A
22

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
Allerus answered 24/6, 2021 at 19:39 Comment(2)
Doh! I was missing the actual gcc for x86_64-unknown-linux-gnu. I didn't realize that. Now it's obvious! Thank you.Unwilled
It would be good to mark this as answeredSavonarola

© 2022 - 2024 — McMap. All rights reserved.