V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dxatgp02
V2EX  ›  Rust

请教 rust 如何做到交叉编译

  •  1
     
  •   dxatgp02 · 24 天前 · 942 次点击

    有一些写好的 rust 想放到 raspi 上面跑试试 网上查了"rust cross compile arm64" 用过

    cargo build --target aarch64-unknown-linux-gnu -r
    

    也试过 cargo 配置文件里加

    [target.aarch64-unknown-linux-gnu]
    linker = "aarch64-linux-gnu-gcc"
    rustflags = ["-L", "/usr/lib/gcc/aarch64-linux-gnu/13.1.0/tmp/usr/lib/"]
    

    都解决不了,放到 raspi 编译一次要很久。

    7 条回复    2025-02-15 09:46:11 +08:00
    tangzs
        1
    tangzs  
       24 天前   ❤️ 1
    安装软件包
    ```
    sudo apt-get install gcc-multilib g++-multilib
    ```
    cargo 配置文件
    ```
    TRIPLET=aarch64-unknown-linux-gnu
    rustup target add $TRIPLET
    cargo build \
    --target $TRIPLET \
    --config target.$TRIPLET.linker=\"aarch64-linux-gnu-gcc\"
    ```
    静态编译
    ```
    TRIPLET=aarch64-unknown-linux-gnu
    rustup target add $TRIPLET
    RUSTFLAGS='-C target-feature=+crt-static' cargo build \
    --target $TRIPLET \
    --config target.$TRIPLET.linker=\"aarch64-linux-gnu-gcc\" \
    --release
    ```
    Nugine0
        2
    Nugine0  
       23 天前   ❤️ 1
    基于 docker 的一键交叉编译 https://github.com/cross-rs/cross

    最近 github actions 出了免费的 arm64 linux runner ,也可以白嫖
    he8822185
        4
    he8822185  
       21 天前   ❤️ 1
    用 cargo-zigbuild
    bli22ard
        5
    bli22ard  
       8 天前   ❤️ 1
    https://www.v2ex.com/t/1096658#r_15657744 17 楼的回答,rust 交叉编译最佳实战
    JohnSmith
        6
    JohnSmith  
       4 天前 via Android   ❤️ 1
    报错信息至少贴出来
    dxatgp02
        7
    dxatgp02  
    OP
       7 小时 45 分钟前
    @JohnSmith 用上面的 zigbuild 能解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2731 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 19ms · UTC 09:31 · PVG 17:31 · LAX 01:31 · JFK 04:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.