Gnoose
Gnoose

Reputation: 105

unresolved import `crate::sys` on rust project building

I am working on the Solana contract with rust language.

When I execute cargo build, it returns ok result.

But when I execute cargo +bpf build --target bpfel-unknown-unknown --release, it returns below the error console.

error[E0432]: unresolved import `crate::sys`
 --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.2/src/sockaddr.rs:5:12
  |
5 | use crate::sys::{
  |            ^^^
  |            |
  |            unresolved import
  |            help: a similar path exists: `crate::socket::io::sys`

error[E0432]: unresolved imports `crate::sys`, `crate::sys`
  --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.2/src/socket.rs:21:12
   |
21 | use crate::sys::{self, c_int, getsockopt, setsockopt, Bool};
   |            ^^^   ^^^^ no `sys` in the root
   |            |
   |            unresolved import
   |            help: a similar path exists: `crate::socket::io::sys`

...

Please let me know if you faced this kinda issue before.

Upvotes: 1

Views: 2616

Answers (1)

Jon C
Jon C

Reputation: 8402

On-chain programs are limited in what resources they can access. For example, you can't access the internet or filesystem. Your program seems to be relying on some of these forbidden packages.

Here's more info from the documentation about using rand, which is also not allowed: https://docs.solana.com/developing/on-chain-programs/developing-rust#depending-on-rand

Upvotes: 1

Related Questions