gpt4 book ai didi

macos - 如何将 Rust 应用程序从 macOS x86 交叉编译到 macOS Silicon?

转载 作者:行者123 更新时间:2023-12-04 01:04:56 31 4
gpt4 key购买 nike

我想将一个 Rust 程序从我的 x86 Mac 交叉编译成一个可以在 Silicon Mac 上运行的二进制文件,但我无法弄清楚链接。
我有:

  • 运行 macOS 10.15.7 Catalina 的 x86 Mac
  • A Rust project called riff
  • cargo 1.51.0 (43b129a20 2021-03-16)最近使用 rustup 检索到
  • Xcode 版本 12.4 (12D4e)

  • 我想把它编译成一个可以在 Silicon (ARM) Mac 上运行的二进制文件。这可能是以下之一:
  • 特定于硅的二进制文件
  • 可以在硅或 x86 上运行的通用二进制文件

  • 我有 tried (通过 ./release.sh --dry) :
  • rustup target add aarch64-apple-darwin
  • cargo build --release --target=aarch64-apple-darwin

  • 结果太长,贴不上来,摘录如下:
       Compiling riff v0.1.0 (/Users/johan/src/riff)
    error: linking with `cc` failed: exit code: 1
    |
    = note: "cc" "-arch arm64" "-L" "/Users/johan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/johan/src/riff/target/aarch64-apple-darwin/release/deps/riff.1g47gi93dk96t2va.rcgu.o" ... "/Users/johan/src/riff/target/aarch64-apple-darwin/release/deps/riff.thread_local-9baf7723f72eef37.thread_local.7fl1y1d9-cgu.9.rcgu.o.rcgu.o" "/Users/johan/src/riff/target/aarch64-apple-darwin/release/deps/riff.unwind-082f7f4ff792426f.unwind.7rkx2ya0-cgu.0.rcgu.o.rcgu.o" "-o /Users/johan/src/riff/target/aarch64-apple-darwin/release/deps/riff" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/johan/src/riff/target/aarch64-apple-darwin/release/deps" "-L" "/Users/johan/src/riff/target/release/deps" "-L" "/Users/johan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/johan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-9eb7dc999785b765.rlib" "-lSystem" "-lresolv" "-lc" "-lm"
    = note: ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libresolv.tbd, missing required architecture arm64 in file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libresolv.tbd
    ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd, missing required architecture arm64 in file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd
    ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libc.tbd, missing required architecture arm64 in file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libc.tbd
    ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, missing required architecture arm64 in file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd
    Undefined symbols for architecture arm64:
    "__tlv_atexit", referenced from:
    std::sys::unix::thread_local_dtor::register_dtor::h4ece0fa32a190720 in riff.std-e40bd6a3af835df4.std.5bd9rdky-cgu.0.rcgu.o.rcgu.o
    ...
    "_free", referenced from:
    alloc::raw_vec::finish_grow::hd210c40bc8674cab (.llvm.18296587876935678160) in riff.addr2line-220464f1af330a49.addr2line.6xizm3st-cgu.1.rcgu.o.rcgu.o
    addr2line::path_push::hf1048f2514c3ed28 in riff.addr2line-220464f1af330a49.addr2line.6xizm3st-cgu.5.rcgu.o.rcgu.o
    alloc::raw_vec::finish_grow::ha5f485527a5c6598 in riff.addr2line-a950b2eed913eb15.addr2line.1hygsg7c-cgu.0.rcgu.o.rcgu.o
    addr2line::path_push::h891160d400ff153e in riff.addr2line-a950b2eed913eb15.addr2line.1hygsg7c-cgu.0.rcgu.o.rcgu.o
    core::ptr::drop_in_place$LT$aho_corasick..prefilter..Packed$GT$::h03bcd2abfab8068d in riff.aho_corasick-5d6c900557669556.aho_corasick.4z4l4vb2-cgu.0.rcgu.o.rcgu.o
    core::ptr::drop_in_place$LT$aho_corasick..packed..pattern..Patterns$GT$::h0c7fda104debb352 in riff.aho_corasick-5d6c900557669556.aho_corasick.4z4l4vb2-cgu.0.rcgu.o.rcgu.o
    core::ptr::drop_in_place$LT$alloc..vec..Vec$LT$alloc..vec..Vec$LT$u8$GT$$GT$$GT$::h75f2b558c0581f8d in riff.aho_corasick-5d6c900557669556.aho_corasick.4z4l4vb2-cgu.0.rcgu.o.rcgu.o
    ...
    (maybe you meant: alloc::alloc::box_free::ha8718384ecb60252 (.llvm.10945926475227631812), alloc::alloc::box_free::h58e664059c03effd (.llvm.10945926475227631812) , alloc::alloc::box_free::h75cae1a8684a32ce (.llvm.8938487907768303252) , alloc::alloc::box_free::h0459f8e1bcc5ae0a (.llvm.8938487907768303252) , alloc::alloc::box_free::hc3b2f94f9be4da06 (.llvm.7882408235892284297) , alloc::alloc::box_free::h75cae1a8684a32ce (.llvm.7882408235892284297) , alloc::alloc::box_free::h0459f8e1bcc5ae0a (.llvm.11547294393004044273) , alloc::alloc::box_free::hcc8806ce168336a8 (.llvm.2537316772799228199) , alloc::alloc::box_free::h305ed20a6d3d49c7 (.llvm.11075277010792284734) , alloc::alloc::box_free::h384e6b725c5ad166 (.llvm.7882408235892284297) , alloc::alloc::box_free::h0459f8e1bcc5ae0a (.llvm.7882408235892284297) , alloc::alloc::box_free::hb8cf920d803cfa22 (.llvm.4992613404806278909) , alloc::alloc::box_free::h90dd1ed16b644fc1 (.llvm.9562203231941335137) , alloc::alloc::box_free::h9e3286b91a0737ba (.llvm.4992613404806278909) , alloc::alloc::box_free::h75cae1a8684a32ce (.llvm.11547294393004044273) )
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    最佳答案

    添加合适的目标

    rustup target add aarch64-apple-darwin
    使用 macOS 11.x SDK 1 编译您的代码:
    SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path) \
    MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version) \
    cargo build --target=aarch64-apple-darwin
    这会生成一个单一架构的二进制文件:
    file target/aarch64-apple-darwin/debug/riff
    target/aarch64-apple-darwin/debug/riff: Mach-O 64-bit executable arm64

    1 — 通过 xcodebuild -showsdks 查找当前可用的 SDK 是什么.

    关于macos - 如何将 Rust 应用程序从 macOS x86 交叉编译到 macOS Silicon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66849112/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com