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

使用anchor build构建Solana NFT程序遇rustc版本兼容问题求助

解决Anchor构建时Solana-Program版本与Rustc版本不匹配问题

问题场景

执行anchor build时触发版本不兼容错误:

error: package solana-program v1.18.11 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.11 --precise ver
where ver is the latest version of solana-program supporting rustc 1.72.0-dev

但全局Rust版本已更新至1.77.0:

rustc --version 
rustc 1.77.0 (aedd173a2 2024-03-17)

解决步骤

1. 强制使用全局稳定Rust工具链构建

Anchor可能默认调用Solana CLI捆绑的旧版Rust工具链,构建时显式指定全局稳定链:

RUSTUP_TOOLCHAIN=stable anchor build

2. 更新Solana CLI至最新版本

旧版Solana CLI自带的Rust工具链可能停留在1.72版本,执行更新:

solana-install update

更新后通过solana --version确认版本,再重新运行anchor build。

3. 检查并更新Anchor CLI版本

确保Anchor版本与Solana 1.18.x兼容,先查看当前Anchor版本:

anchor --version

若版本低于0.29.x,执行Anchor CLI更新:

cargo install --git https://github.com/coral-xyz/anchor anchor-cli --locked

4. 清理Cargo缓存并重新构建

缓存的旧依赖可能导致版本冲突,清理后重试:

cargo clean
anchor build

5. 确认Cargo.toml依赖配置

打开项目根目录的Cargo.toml,由于你的Rust版本(1.77.0)满足solana-program v1.18.11的1.75+要求,直接保留如下依赖声明即可:

solana-program = "1.18.11"

内容的提问来源于stack exchange,提问作者Hemang Joshi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 06:47:39