为什么要“锚定建造”?和“Cargo build-bpf”显示错误的 rustc 版本?
我正在尝试构建 (https://github.com/betterclever/solend-anchor) 使用 anchor build
打包,但是我收到以下错误
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 时导致问题的原因是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
anchor build
和cargo build-bpf
使用与系统中包含的普通rustc
编译器不同的编译器,因此它们报告不同的结果是正常的版本。 BPF 编译器附带 Solana 工具套件。如果您的计算机上已安装 Solana 工具,则只需运行:
如果没有,则可以运行:
这将为您提供所有最新工具,包括 BPF 编译器。
anchor build
andcargo build-bpf
use a different compiler than the normalrustc
compiler included in the system, so it's normal that they report a different version. The BPF compiler comes with the Solana tool suite.If you already have the Solana tools installed on your computer, you can simply run:
And if you don't, you can run:
That will give you all of the newest tools, including the BPF compiler.
我有 Solana 最新版本,在编译下载的程序之一时遇到了同样的错误。
命令
对我有用。
I have Solana latest version, I faced the same error while compiling one of the downloaded program.
Command
Worked for me.
发生此问题的原因通常是 Solana BPF 工具链使用单独的 Rust 版本,
因此 BPF 工具链并不总是使用与系统默认版本相同的 Rust 版本,这就是为什么您会看到命令版本
和锚定构建版本 不同的原因正在使用。
要解决此问题,您需要确保 Solana BPF 工具链使用正确的 Rust 版本,您需要专门针对 BPF 更新 Rust 版本,
您可以通过运行此命令
并设置 Anchor Build 的环境变量来实现 这一点将 BPF_RUSTC 环境变量设置为版本 1.69 的 Rust 安装的正确路径。
您可以通过将以下内容添加到 shell 配置文件(例如 .bashrc、.zshrc)来完成此操作:
This issue usually happens cause Solana BPF toolchain uses a separate version of Rust
so the BPF toolchain does not always use the same Rust version as your system default, which is why you're seeing a different version with the command
and the version that anchor build is using.
To fix this you need to ensure that the correct Rust version is used by the Solana BPF toolchain, you’ll need to update the Rust version specifically for BPF
you can do that by running this command
and set the Environment Variable for Anchor Build set the BPF_RUSTC environment variable to the correct path of your Rust installation with version 1.69.
You can do this by adding the following to your shell configuration file (e.g., .bashrc, .zshrc):