在Mac OSX上交叉编译到x86_64-unknown-linux-gnu失败

时间:2016-11-04 13:44:23

标签: linux macos rust cross-compiling rust-cargo

我尝试将我的一个Rust项目编译到x86_64-unknown-linux-gnu目标:

$ 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)

我不知道如何处理这样的消息。我该怎么做才能让它发挥作用?

这是我的Cargo.toml文件:

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

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

货物版本:

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

Rust版本:

rustc 1.12.0 (3191fbae9 2016-09-23)

我尝试用rustup更新所有内容,但我仍然遇到同样的问题。

1 个答案:

答案 0 :(得分:1)

受到 cross-compile-rust-from-mac-to-linux 的启发,我通常会安装这些依赖项来将 Rust 从 Mac OS 交叉编译到 Linux(例如用于 Docker 容器):

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

最后我可以在 Mac OS 上交叉编译到 Linux:

CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc \
cargo build --target=x86_64-unknown-linux-gnu