【问题标题】:Cargo Fails to Compile hyper with Darwin TargetCargo 无法使用 Darwin Target 编译 hyper
【发布时间】:2021-07-13 04:22:45
【问题描述】:

我有一个我编写的 CLI,并试图在基于 rust:1.53-slim 映像的 Docker 映像中为这些目标构建它:

  • x86_64-unknown-linux-gnu
  • x86_64-apple-darwin
  • x86_64-pc-windows-gnu

Linux 和 Windows 目标正在正确构建,但是当我尝试对 Darwin 目标进行交叉编译时,hyper crate 由于以下错误继续无法编译:

$ cargo build --locked --release --target x86_64-apple-darwin

# ...
# OMITTED COMPILE OUTPUTS
# ...

= note: cc: error: x86_64: No such file or directory
          cc: error: unrecognized command line option '-arch'; did you mean '-march='?
          

error: aborting due to previous error

error: could not compile `hyper`

我在互联网上搜索了此问题的线索或解决方案,但找不到任何有用的信息。有没有人经历过或解决过这个问题?任何指导都会很棒!


编辑:

是否需要通过apt-get 安装 GCC 链接器才能正确编译 darwin?

【问题讨论】:

    标签: rust rust-cargo hyper


    【解决方案1】:

    交叉编译仍然需要支持所请求目标的本机链接器(这反过来又需要系统库)。

    您可能对osxcross 或crossbuild 有一些运气,并使用.cargo/config.toml 中的特定于目标的部分覆盖链接器(和c 编译器),例如:

    [target.x86_64-apple-darwin]
    linker = "linker-path-here"
    

    和/或将CC env var 设置为正确的交叉编译器。

    【讨论】:

    • 我需要在 docker 镜像上通过apt-get 安装什么东西才能使 darwin 链接器可用,还是在添加 rustup 目标时安装?
    猜你喜欢
    • 2015-12-13
    • 2022-01-20
    • 2022-09-25
    • 2018-10-19
    • 1970-01-01
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 2020-07-16
    相关资源
    最近更新 更多