I need to generate random numbers. For that, I define in my Cargo.toml
file the following:
[package]
name = "dice"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"
[lib]
crate-type = ["cdylib", "lib"]
name = "dice"
doctest = false
[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []
[dependencies]
rand = "0.8.5"
When I run anchor build
in console, I get the following error:
BPF SDK: /home/krl/.local/share/solana/install/releases/1.9.13/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
Compiling getrandom v0.2.6
error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
--> ~.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.6/src/lib.rs:240:9
|
240 | / compile_error!("target is not supported, for more information see: \
241 | | https://docs.rs/getrandom/#unsupported-targets");
| |_________________________________________________________________________^
error[E0433]: failed to resolve: use of undeclared crate or module `imp`
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.6/src/lib.rs:262:5
|
262 | imp::getrandom_inner(dest)
| ^^^ use of undeclared crate or module `imp`
For more information about this error, try `rustc --explain E0433`.
After a search, I found the same problem in https://users.rust-lang.org/t/use-of-undeclared-crate-or-module-imp-on-getrandom-0-2-3-when-building-for-wasm32-unknown-unknown/70171, whose solution is to add in Cargo.toml
:
getrandom = { version = "0.2", features = ["js"] }
However, it doesn't work for me.