totdking
totdking

Reputation: 1

how to solve cargo build-bpf / anchor build error on wsl ubuntu latest version

error: failed to parse lock file at: /home/totdking/SolanaUbuntu/token_raffle/Cargo.lock

Caused by: lock file version 4 requires -Znext-lockfile-bump

This error was gotten while i tried to run the anchor build command on my command line

I tried changing the rust version, using older and newer versions, rebuilt the cargo.lock file, added required dependencies to my cargo .toml, used several versions of solana cli, reinstalled the anchor, used nightly versions of rust all to be met with the same error

Upvotes: 0

Views: 723

Answers (3)

RastaDjust
RastaDjust

Reputation: 1

i think this can help also: Wrong Solana version the error is du to anchor using cargo and rustc from within your Solana release not rustup update toolchains...

One thing that worked was opening corgo.lock file and putting a "3" in version instead of 4.... It will compile but you'll run into a rusc or cargo using 1.79 but you are using 1.75... Rustup update won't fix that as i said it uses rust from within solana...

To fix both errors

just update your bsolana cli --version to a 2.1.x version just go take a look at the different solana-program versions and rust version at crates.io... you can go chexk out solana-program versions and rust requierments here:

Solana-program at crates.io

solana-program@=>2.1.0

using rust crates, its best to match all basiv solana instances to same version and also to use the same cli version ex: solana-program: 2.1.11 solana-sdk: 2.1.11, solana-???? 2.1.11 all the same.

Then update your solana using:

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

just replace /stable with v^2.1.0 or any version above 2.1.x

Then if you run into dependencies problems use the same crates.io link and search for crate or dependency and look at its dependencies and match.. Generally cargo add fetches the right version if no entry is present...

Upvotes: 0

RastaDjust
RastaDjust

Reputation: 1

I was getting this berror when cargo build-sbf or anchor build:

cargo build-sbf
error: failed to parse lock file at: /home/anrchsun/devs/ana-cain/Cargo.lock

but if you all could read carefully the solution was given in error message:

Caused by:

lock file version 4 requires -Znext-lockfile-bump

so I ran

cargo build-sbf -- -Znext-lockfile-bump

and everything worked fine...

Compiling borsh v0.9.3
Compiling anchor-attribute-access-control v0.30.1
Compiling anchor-attribute-account v0.30.1
Compiling anchor-attribute-error v0.30.1
Compiling anchor-attribute-event v0.30.1
Compiling anchor-attribute-constant v0.30.1
Compiling anchor-derive-serde v0.30.1
Compiling anchor-attribute-program v0.30.1
Compiling anchor-derive-accounts v0.30.1
^[[B Building [=======================> ] 165/169: solana-program, solana-program
Compiling anchor-lang v0.30.1
Compiling ana-chain v0.0.0 (/home/anrchsun/devs/ana-cain/program)
Finished release [optimized] target(s) in 1m 31s..

Upvotes: 0

Edoardo Berardo
Edoardo Berardo

Reputation: 172

Please open the "Cargo.lock" file within your anchor project, manually update the "version" to 3 instead of 4, and try to build again.

The error "Caused by: lock file version 4 requires -Znext-lockfile-bump" might occur to Window users because the Cargo.lock file, which is generated by Rust's package manager (Cargo), is in a format (version 4) that is not recognized by the version of Cargo installed on the user's system. Many Windows users might have an older version of Rust installed by default or through older guides/tools, especially if they installed Rust via methods that do not automatically update (e.g., standalone installers or custom configurations). Anchor and Solana projects often require the latest Rust version to work seamlessly, as they use cutting-edge features.

Upvotes: 1

Related Questions