开发者问题收集

Solana Rust 智能合约构建错误:构建失败

2021-11-17
1397

我是 Solana/Rust 的初级开发者。 作为我的第一个 Solana 项目,我构建了 mint NFT 合约。 然后我想部署合约。 因此,为了获取编译后的输出 .so 文件,我确实运行了如下命令: cargo build , 但出现了以下错误:

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

这是 build.rs 文件:

// 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");
}

这是 Cargo.toml 文件:

[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"

我使用的是 ubuntu 18.04、cargo 1.56.0。

我做错了什么?

3个回答

如果您尝试构建 Rust Solana 程序(即智能合约),则只需要 cargo build-bpf ,因为程序会通过 LLVM 编译为 BPF,这就是在 Solana 上部署的内容

Frank C.
2021-11-18

这似乎是一个兼容性问题。安装最新版本的 rustc

此外,当您安装 solana 工具包时:

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

请确保更新 PATH 环境变量以包含 solana 程序:

Yilmaz
2022-01-25

我认为 Solana 稳定版本解决了你的问题。

sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
Vitor Ribeiro
2022-12-02