You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Anchor构建项目遇多版本冲突问题求助

问题描述

使用Anchor构建项目时执行anchor build报错:

package solana-program v1.18.8 cannot be built because it requires rustc 1.75.0 or newer, while the currently active rustc version is 1.72.0-dev
Either upgrade to rustc 1.75.0 or newer, or use
cargo update -p solana-program@1.18.8 --precise ver
where ver is the latest version of solana-program supporting rustc 1.72.0-dev

但本地rustc --version显示为1.77.0,solana-cli --version为1.18.1,执行cargo-build-sbf --version却返回:

solana-cargo-build-sbf 1.18.1
platform-tools v1.39
rustc 1.72.0

已更新rustup toolchain但问题未解决,尝试执行cargo install solana-cargo-build-sbf --force时出现:

Updating crates.io index
error: could not find solana-cargo-build-sbf in registry crates-io with version `=1.19.0

解决方案
  • 清理Solana工具链缓存
    执行以下命令删除旧的工具链缓存,避免版本冲突:

    sudo rm -rf ~/.cache/solana/
    rm -rf ~/.local/share/solana/install/active_release/
    
  • 重新安装匹配版本的Solana工具链
    因为你的solana-cli版本是1.18.1,直接通过官方工具重新初始化对应版本的环境,它会自动安装适配的sbf工具链和rust版本:

    solana-install init 1.18.1
    

    执行完成后重启终端,再检查cargo-build-sbf --version,确认rust版本已同步。

  • 绑定项目到Solana SBF工具链
    在项目根目录创建rust-toolchain.toml文件,内容如下,强制项目使用Solana提供的sbf工具链:

    [toolchain]
    channel = "solana-sbf"
    
  • 清理Anchor缓存后重新构建
    先清理Anchor的编译缓存,再执行构建:

    anchor clean
    anchor build
    
  • 关于solana-cargo-build-sbf安装错误的说明
    该工具并非通过crates.io单独安装,而是随Solana CLI一起分发的,所以不要用cargo install命令安装它,通过上述solana-install命令即可获取对应版本的工具。

内容的提问来源于stack exchange,提问作者Osman Ghani Granday

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 05:58:32