Solana Rust smart contract build error: build failed - rust

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 (i.e. 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)"

Related

EGui with glfw in rust

Currently learning openGL in rust and decided to add e-gui, to make immediate changes.
Decided to use this crate: https://crates.io/crates/egui_glfw_gl/0.13.1
After adding it to Cargo.toml can't build or run.
PS opengl_t_2> cargo run
Compiling glfw-sys v3.3.5
error: failed to run custom build command for `glfw-sys v3.3.5`
Caused by:
process didn't exit successfully: `opengl_t_2\target\debug\build\glfw-sys-d98b92fc73a7f019\build-script-build` (exit code: 101)
--- stdout
CMAKE_TOOLCHAIN_FILE_x86_64-pc-windows-msvc = None
CMAKE_TOOLCHAIN_FILE_x86_64_pc_windows_msvc = None
HOST_CMAKE_TOOLCHAIN_FILE = None
CMAKE_TOOLCHAIN_FILE = None
CMAKE_GENERATOR_x86_64-pc-windows-msvc = None
CMAKE_GENERATOR_x86_64_pc_windows_msvc = None
HOST_CMAKE_GENERATOR = None
CMAKE_GENERATOR = None
CMAKE_PREFIX_PATH_x86_64-pc-windows-msvc = None
CMAKE_PREFIX_PATH_x86_64_pc_windows_msvc = None
HOST_CMAKE_PREFIX_PATH = None
CMAKE_PREFIX_PATH = None
CMAKE_x86_64-pc-windows-msvc = None
CMAKE_x86_64_pc_windows_msvc = None
HOST_CMAKE = None
CMAKE = Some("C:\\Program Files\\CMake\\bin\\")
running: "C:\\Program Files\\CMake\\bin\\" "C:\\Users\\Vasily\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\glfw-sys-3.3.5\\." "-G" "Visual Studio 16 2019" "-Thost=x64" "-Ax64" "-DGLFW_BUILD_EXAMPLES=OFF" "-DGLFW_BUILD_TESTS=OFF" "-DGLFW_BUILD_DOCS=OFF" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_PREFIX=opengl_t_2\\target\\debug\\build\\glfw-sys-52652cf8f267b532\\out" "-DCMAKE_C_FLAGS= -nologo -MD -Brepro" "-DCMAKE_C_FLAGS_DEBUG= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS_DEBUG= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS_DEBUG= -nologo -MD -Brepro"
"-DCMAKE_BUILD_TYPE=Debug"
--- stderr
thread 'main' panicked at '
failed to execute command: program path has no file name
Cargo.toml:
[dependencies]
cgmath = "0.16.1"
gl = "0.10.0"
image = "0.19.0"
tobj = "0.1.6"
num = "0.2.0"
rand = "0.5.5"
egui = "0.17.0"
egui_glfw_gl = "0.13.1"
[dependencies.glfw]
git = "https://github.com/bjz/glfw-rs.git"
default-features = false
Without egui-glfw, everything builds and I have a functional 3d scene.
File structure
I apologize, if this is a stupid question, but I have already tried everything.
CMAKE = Some("C:\\Program Files\\CMake\\bin\\")
For whatever reason, your CMAKE environmental variable is pointing to a directory rather than the cmake.exe binary.
Make sure that you have cmake installed, and edit your CMAKE envvar to point to it. Or remove it, if cmake is in your PATH.

Run code with cargo run on Raspberry Pi Pico using elf2uf2-rs

I try to run Rust code on a Raspberry Pi Pico. A simple "blink" example application is successfully (as it seems) built using:
cargo build --release --target=thumbv6m-none-eabi
I have installed elf2uf2-rs with:
cargo install elf2uf2-rs
And I then try to run the blink application on the Raspberry Pi Pico using:
cargo run --release --target=thumbv6m-none-eabi
but it fails with this message, where "rp2" is the name of my binary:
target/thumbv6m-none-eabi/release/rp2: cannot execute binary file
Any suggestions on what can be wrong?
This is my Cargo.toml:
[package]
name = "rp2"
version = "0.1.0"
edition = "2021"
[dependencies]
rp2040-hal = "0.3.0"
cortex-m = "0.7.2"
embedded-hal = { version = "0.2.5", features = ["unproven"] }
eh1_0_alpha = { version="=1.0.0-alpha.6", package="embedded-hal", optional=true }
embedded-time = "0.12.0"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
cortex-m-rt = "0.7"
rp-pico = "0.2.0"
[dev-dependencies]
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
Update
I now added a file .cargo/config.toml with this content:
# Choose a default "cargo run" tool.
# probe-run is recommended if you have a debugger
# elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# runner = "probe-run --chip RP2040"
runner = "elf2uf2-rs -d"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# Code-size optimizations.
# trap unreachable can save a lot of space, but requires nightly compiler.
# uncomment the next line if you wish to enable it
# "-Z", "trap-unreachable=no",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
]
[build]
target = "thumbv6m-none-eabi"
and a memory.x file with this content:
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}
EXTERN(BOOT2_FIRMWARE)
SECTIONS {
/* ### Boot loader */
.boot2 ORIGIN(BOOT2) :
{
KEEP(*(.boot2));
} > BOOT2
} INSERT BEFORE .text;
but then the cargo build --release command fails with this error:
error: linking with `rust-lld` failed: exit status: 1
...
= note: rust-lld: error: cannot find linker script defmt.x
I use a MacBook with M1 Apple Silicon chip, this might be a related issue rust-lld problem under AArch64 system.
I have now got the code running on the Raspberry Pi Pico.
The first problem was that I hadn't created the .cargo/config.toml file that contains the instruction to "run" with elf2uf2:
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"
The other problem was that my .cargo/config.toml also contained this reference to defmt that I didn't have on my system, so when commenting out this line (under rustflags), the code compiled with cargo build --release and it was run on the Raspberry Pi Pico with cargo run --release:
# "-C", "link-arg=-Tdefmt.x",

Rust .exe fails to open on Windows

I'm building an app with rust. Using --cargo run --release successfully compiles the app and runs it, bringing up the GUI window for the app. However, when I manually open target/release/MyApp.exe, nothing happens. Checked when myapp.exe was last modifies shows that running --cargo run --release is updating the app.
I'm on windows 10 so I added "x86_64-pc-windows-msvc" as the build target.
[package]
name = "MuTexAlpha"
version = "0.1.0"
authors = ["Webb Hinton <wyhinton189#gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fltk = "0.15.1"
serde = "1.0.118"
texture-synthesis = "0.8.0"
rand = "0.7.3"
num_cpus = "1.13.0"
uuid = { version = "0.8", features = ["serde", "v4"] }
image = "0.23.12"
glob = "0.3.0"
dyn-clone = "1.0.4"
colored = "2.0.0"
arboard = "1.1.0"
id_tree = "1.7.0"
id_tree_layout = "2.0.1"
typetag = "0.1"
serde_json = "1.0.61"
snafu = "0.6.10"
palette = "0.5.0"
indicatif = "0.14.0"
[build]
target = "x86_64-pc-windows-msvc"
Isn't the .exe in release the same program being executed with --cargo run --release?
I have some file dependencies in my app, might this be the cause of the issue? (compiling the app gives no errors, however)
Could this be something specifically related to windows?
Might just be a shot in the dark, but are you opening the exe using Windows Explorer?
Open up a cmd.exe window and try running it from there.

Rust: Cargo.toml error: expected item, found `[`, when trying to include nalgebra

[package]
name = "my package"
version = "0.1.0"
authors = ["me"]
edition = "2018"
[dependencies]
nalgebra = "0.18.1"
I tried to compile rust with above Cargo.toml but it gave me following error:
error: expected item, found `[`
--> Cargo.toml:1:1
|
1 | [package]
| ^ expected item
error: aborting due to previous error
I can fix this if I remove nalgebra = "0.18.1", but I can't use nalgebra package so it doesn't help me.
I think there are multiple issues with your Cargo.toml
This is not allowed:
name = "my package"
Suggestion:
name = "my-package"
There is also missing parts:
error during execution of `cargo metadata`: error: failed to parse manifest at `test/Cargo.toml`
Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present
Could you post the entire file here?
A minimum viable setup:
[package]
name = "my-package"
version = "0.1.0"
authors = ["me"]
edition = "2018"
[[bin]]
name = "radkilla"
path = "src/main.rs"
doc = false
[dependencies]
nalgebra = "0.18.1"
src/main.rs
fn main() {}
Running fmt and build:
➜ test cargo fmt ; cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.11s
The error disappeared after closing the cargo.toml file which was opened on the visual studio.

Cargo can't parse the Cargo.toml for url version 0.5.7

I encountered a problem when running cargo build:
/usr/local/bin/cargo build --color=always
error: unable to get packages from source
Caused by:
failed to parse manifest at `/home/lzc/.multirust/toolchains/stable/cargo/registry/src/github.com-1ecc6299db9ec823/url-0.5.7/Cargo.toml`
Caused by:
could not parse input as TOML
Caused by:
expected newline, found an identifier at line 14
I found this issue on GitHub, but it didn't solve my problem.
This is my project Cargo.toml:
[dependencies]
hyper = "0.7.2"
rustc-serialize = "0.3"
websocket = "0.15.1"
And my rustc and cargo version:
➜ ~ cargo -V
cargo 0.18.0 (fe7b0cdcf 2017-04-24)
➜ ~ rustc -V
rustc 1.17.0 (56124baa9 2017-04-24)
And here is the file Cargo complains about(/home/lzc/.multirust/toolchains/stable/cargo/registry/src/github.com-1ecc6299db9ec823/url-0.5.7/Cargo.toml):
[package]
name = "url"
version = "0.5.7"
authors = [ "Simon Sapin <simon.sapin#exyr.org>" ]
description = "URL library for Rust, based on the WHATWG URL Standard"
documentation = "http://servo.github.io/rust-url/url/index.html"
repository = "https://github.com/servo/rust-url"
readme = "README.md"
keywords = ["url", "parser"]
license = "MIT/Apache-2.0"
[[test]] name = "format" #<- line 14
[[test]] name = "form_urlencoded"
[[test]] name = "idna"
[[test]] name = "punycode"
[[test]] name = "tests"
[[test]]
name = "wpt"
harness = false
[dev-dependencies]
rustc-test = "0.1"
[features]
query_encoding = ["encoding"]
serde_serialization = ["serde"]
heap_size = ["heapsize", "heapsize_plugin"]
[dependencies.heapsize]
version = ">=0.1.1, <0.4"
optional = true
[dependencies.heapsize_plugin]
version = "0.1.0"
optional = true
[dependencies.encoding]
version = "0.2"
optional = true
[dependencies.serde]
version = ">=0.6.1, <0.8"
optional = true
[dependencies]
uuid = "0.1.17"
rustc-serialize = "0.3"
unicode-bidi = "0.2.3"
unicode-normalization = "0.1.2"
matches = "0.1"
As listed in the url crate's GitHub issue, it previously used a form of TOML that was actually invalid. Newer versions of Cargo no longer parse that invalid form.
Nothing in your shown dependency list requires url version 0.5.7. url version 0.5.10 has been released, so perform a cargo update to switch to it. Note that 0.5.10 was published on Aug 21, 2016, so it's almost a year old at this point.

Resources