为什么 "anchor build" 和 "Cargo build-bpf" 显示错误的 rustc 版本?

Why is "anchor build" and "Cargo build-bpf" showing wrong rustc version?

我正在尝试使用 anchor build 构建 (https://github.com/betterclever/solend-anchor) 包,但是我收到以下错误

error: package `uint v0.9.3` cannot be built because it requires rustc 1.56.1 or newer, while the currently active rustc version is 1.56.0-dev

我更新了 rustc 并且 运行 命令 rustup default nightly 显示:

info: using existing install for 'nightly-x86_64-apple-darwin'
info: default toolchain set to 'nightly-x86_64-apple-darwin'

  nightly-x86_64-apple-darwin unchanged - rustc 1.61.0-nightly 

所以它告诉我安装和活动的 rustc 版本是 1.61,但是由于某种原因锚构建没有找到它。我也试过 运行 cargo build-bpf 但同样的事情不断发生。 cargo build似乎工作正常。 我想知道 运行 anchor build 和 cargo build-bpf 时出现问题的原因是什么?

anchor buildcargo build-bpf 使用与系统中包含的正常 rustc 编译器不同的编译器,因此它们报告不同的版本是正常的。 BPF 编译器附带 Solana 工具套件。

如果您的计算机上已经安装了 Solana 工具,您只需 运行:

solana-install init 1.9.13

如果你不这样做,你可以 运行:

sh -c "$(curl -sSfL https://release.solana.com/v1.9.13/install)"

这将为您提供所有最新的工具,包括 BPF 编译器。