简体   繁体   中英

Solana Rust smart contract build error: build failed

I am a beginner Solana/Rust developer. As my first Solana project, I built the mint NFT contract. And then I want to deploy the contract. So to get the compiled output .so file, I did run like: cargo build , but getting this error:

warning: cc: warning: src/main.rs: linker input file unused because linking not done
warning: ar: /home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-7f2fc6a536921641/out/src/main.o: No such file or directory

error: failed to run custom build command for `solana-nft v0.1.0 (/home/rango/my_tasks/mintdropz/solana-nft-contract)`

Caused by:
  process didn't exit successfully: `/home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-cbb36a23539fa380/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-changed=src/main.rs
  TARGET = Some("x86_64-unknown-linux-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_x86_64-unknown-linux-gnu = None
  CC_x86_64_unknown_linux_gnu = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-unknown-linux-gnu = None
  CFLAGS_x86_64_unknown_linux_gnu = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-7f2fc6a536921641/out/src/main.o" "-c" "src/main.rs"
  cargo:warning=cc: warning: src/main.rs: linker input file unused because linking not done
  exit status: 0
  AR_x86_64-unknown-linux-gnu = None
  AR_x86_64_unknown_linux_gnu = None
  HOST_AR = None
  AR = None
  running: "ar" "cq" "/home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-7f2fc6a536921641/out/libhello.a" "/home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-7f2fc6a536921641/out/src/main.o"
  cargo:warning=ar: /home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-7f2fc6a536921641/out/src/main.o: No such file or directory
  exit status: 1

  --- stderr


  error occurred: Command "ar" "cq" "/home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-7f2fc6a536921641/out/libhello.a" "/home/rango/my_tasks/mintdropz/solana-nft-contract/target/debug/build/solana-nft-7f2fc6a536921641/out/src/main.o" with args "ar" did not execute successfully (status code exit status: 1).


warning: build failed, waiting for other jobs to finish...
error: build failed

this is build.rs file:

// Example custom build script.
fn main() {
  // Tell Cargo that if the given file changes, to rerun this build script.
  println!("cargo:rerun-if-changed=src/main.rs");
  // Use the `cc` crate to build a C file and statically link it.
  cc::Build::new()
    .file("src/main.rs")
    .compile("hello");
}

this is Cargo.toml file:

[package]
name = "solana-nft"
version = "0.1.0"
edition = "2018"

[dependencies]
solana-client = "1.7.8"
solana-sdk = "1.7.8"
spl-token = { version = "3.2.0", features = [ "no-entrypoint" ] }
rand = "0.8.4"
solana-program = "1.7.11"
spl-token-metadata = "0.0.1"
openssl = { version = "0.10", features = ["vendored"] }

[build-dependencies]
cc = "1.0"
bindgen = "0.53.1"

I am using ubuntu 18.04, cargo 1.56.0.

What am I doing wrong?

If you are trying to build a Rust Solana Program (ie Smart Contract) you only need to cargo build-bpf as Programs get compiled to BPF through LLVM and that is what is deployed on Solana

This seems to be a compatible issue. install the latest version of rustc

Also when u install the solana toolkit:

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

Make sure you update your PATH environment variable to include the solana programs:

I think Solana stable version solves your problem.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM