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

Anchor v0.30.1与Solana v1.18.17类型不匹配错误求助

Solana智能合约开发:Anchor依赖版本冲突解决

解决步骤

  • 强制统一solana_program版本
    在项目根目录的Cargo.toml中添加补丁块,锁定solana_program版本为与你的Solana CLI和Anchor兼容的1.18.17:
    [patch.crates-io]
    solana_program = { version = "=1.18.17" }
    
  • 同步Anchor相关依赖版本
    确保Cargo.toml中anchor-lang和anchor-spl版本完全一致,比如:
    anchor-lang = "0.30.1"
    anchor-spl = "0.30.1"
    
  • 清理缓存并重新构建
    执行命令清除旧依赖缓存,避免残留的多版本文件干扰:
    cargo clean
    cargo build-sbf
    

问题原因

  • Anchor框架对solana_program有严格的版本依赖,Anchor v0.30.1本身绑定了特定版本的solana_program。当引入anchor_spl::token模块时,如果anchor-spl依赖的solana_program版本与项目中其他依赖(包括Solana CLI对应的版本)不一致,就会导致类型不匹配——不同版本的solana_program导出的Pubkey、Instruction等类型会被Rust视为完全不同的类型,即使结构一致。
  • 你添加的std::cmp::min本身不会引发冲突,只是引入anchor-spl模块时触发了隐藏的多版本依赖问题。

内容的提问来源于stack exchange,提问作者Rex Dev

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 19:37:08