Dixan
Dixan

Reputation: 317

Rust version problem when running cargo build-bpf

I am trying to run cargo build-bpf on a basic start rust program.

I installed Rust with the curl command curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh.

When I run cargo --version I get cargo 1.75.0 (1d8b05cdd 2023-11-20). When I run rustc --version I get rustc 1.75.0 (82e1608df 2023-12-21).

But in my project directory, when I run cargo build-bpf I get an error saying:

error: package `package` cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev

How is it using version 1.68.0-dev? I tried running rustup update but I still get the 1.68.0-dev error?

Upvotes: 2

Views: 6661

Answers (4)

Eric
Eric

Reputation: 24984

Cause of the issue:

installed cargo build-sbf used a rustc that is too low, which is not your local rustc version.

How to fix:

  • cargo build-sbf --version # check the rustc version in output, if indeed too low, then continue.
  • Go to https://github.com/anza-xyz/agave/releases, to find the latest release.
  • agave-install init v2.1.7 # replace the version with latest from github
  • cargo build-sbf --version # check the rustc version again.
  • then try cargo build-bpf again

Upvotes: 0

czz mj
czz mj

Reputation: 1

sh -c "$(curl -sSfL https://release.anza.xyz/v2.1.0/install)"

agave-install update

then problem been solved

Upvotes: -1

lixin yang
lixin yang

Reputation: 1

If you're on macos, make sure your rust is downloaded natively and not from homebrew!

Don't doubt it's the version of solana-install, go to https://crates.io/crates/solana-install/versions and check the latest version, for example it's currently 1.18.18, then solana-install init 1.18.18, and then it's Then you can continue to anchor build :)

Upvotes: -1

Dixan
Dixan

Reputation: 317

I ran solana-install update and it said "Install is up to date".

Ran cargo build-bpf again and got error:

error: package `solana-program v1.18.1` cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev
Either upgrade to rustc 1.72.0 or newer, or use
cargo update -p [email protected] --precise ver
where `ver` is the latest version of `solana-program` supporting rustc 1.68.0-dev

To fix it I ran the following: solana-install init 1.18.1 and then when I ran cargo build-bpf again it worked.

Upvotes: 4

Related Questions