为什么要“锚定建造”?和“Cargo build-bpf”显示错误的 rustc 版本?

发布于 2025-01-16 11:44:02 字数 813 浏览 2 评论 0 原文

我正在尝试构建 (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 时导致问题的原因是什么?

I'm trying to build the (https://github.com/betterclever/solend-anchor) package using anchor build, however I get the following error

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

I updated rustc and running the command rustup default nightlyshows:

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 

So it shows me that the installed and active rustc version is 1.61, however anchor build is not finding that for some reason. I also tried running cargo build-bpf but the same thing kept happening. cargo buildseemed to work fine.
I'm wondering what is causing the problem when running anchor build and cargo build-bpf?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

携君以终年 2025-01-23 11:44:02

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 编译器。

anchor build and cargo build-bpf use a different compiler than the normal rustc 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:

solana-install init 1.9.13

And if you don't, you can run:

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

That will give you all of the newest tools, including the BPF compiler.

怀里藏娇 2025-01-23 11:44:02

我有 Solana 最新版本,在编译下载的程序之一时遇到了同样的错误。
命令

solana-install update

对我有用。

I have Solana latest version, I faced the same error while compiling one of the downloaded program.
Command

solana-install update

Worked for me.

难得心□动 2025-01-23 11:44:02

发生此问题的原因通常是 Solana BPF 工具链使用单独的 Rust 版本,

因此 BPF 工具链并不总是使用与系统默认版本相同的 Rust 版本,这就是为什么您会看到命令版本

rustc --version

和锚定构建版本 不同的原因正在使用。

要解决此问题,您需要确保 Solana BPF 工具链使用正确的 Rust 版本,您需要专门针对 BPF 更新 Rust 版本,

您可以通过运行此命令

rustup toolchain install bpf --component rust-std --target bpfel-unknown-unknown

并设置 Anchor Build 的环境变量来实现 这一点将 BPF_RUSTC 环境变量设置为版本 1.69 的 Rust 安装的正确路径。

您可以通过将以下内容添加到 shell 配置文件(例如 .bashrc、.zshrc)来完成此操作:

export BPF_RUSTC=~/.rustup/toolchains/bpf/bin/rustc

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

rustc --version

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

rustup toolchain install bpf --component rust-std --target bpfel-unknown-unknown

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):

export BPF_RUSTC=~/.rustup/toolchains/bpf/bin/rustc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文