无法为 solana 部署生成 .so 文件。 (没有错误)
Unable to generate .so file for solana deployment. (No errors)
我试图通过自己重写 Rust 库来理解 solana/example-helloworld
。我已经这样做了,并从 package.json 文件生成了 .so
文件,以下是 运行:
cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program
我在上面使用是因为我已经在本地设置了 cargo 并且 运行 上面针对我的设置,我遇到了一些问题,从版本(使用 2021,不得不降级到 2018)到不得不重命名main.rs
到 lib.rs
和其他我不记得了。
下面是我在 Cargo.toml 文件所在的项目根目录中的终端的实际 运行ning 命令:
cargo build-bpf --manifest-path=./Cargo.toml --bpf-out-dir=dist/program
但是在运行ning上面,在dist目录下,什么都没有
这实际上是一个多层次的问题:
.so
文件是指 solana 文件,对吧?
cargo build-bpf
是什么意思?
- 为什么 2021 版不适用于 solana 示例,有什么原因吗?
- 最后,为什么上面的命令没有输出我的
.so
文件?
下面我的Cargo.toml:
[package]
name = "jjoek-sc"
version = "0.0.1"
description = "My first rust program for solana (hello john)"
authors = ["JJoek <info@jjoek.com>"]
license = "Apache-2.0"
homepage = "https://jjoek.com/"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
borsh = "0.9.1"
borsh-derive = "0.9.1"
solana-program = "~1.8.14"
下面是我的lib.rs
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint,
entrypoint::ProgramResult,
pubkey::Pubkey,
msg,
program_error::ProgramError,
};
/// Define the type of state stored in accounts
#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct GreetingAccount {
/// number of greetings
pub counter: u32,
}
// Declare and export the program's entrypoint
entrypoint!(process_instruction);
// Program entrypoint's implementation
pub fn process_instruction(program_id: &Pubkey, accounts: &[AccountInfo], _instruction_data: &[u8]) -> ProgramResult {
msg!("Hello, John everything is gonna be okay");
msg!("Hello World Rust program entrypoint");
// Iterating accounts is safer than indexing
let accounts_iter = &mut accounts.iter();
// Get the account to say hello to
let account = next_account_info(accounts_iter)?;
// The account must be owned by the program in order to modify its data
if account.owner != program_id {
msg!("Greeted account does not have the correct program id");
return Err(ProgramError::IncorrectProgramId);
}
// Increment and store the number of times the account has been greeted
let mut greeting_account = GreetingAccount::try_from_slice(&account.data.borrow())?;
greeting_account.counter += 1;
greeting_account.serialize(&mut &mut account.data.borrow_mut()[..])?;
msg!("Greeted {} time(s)!", greeting_account.counter);
Ok(())
}
.so file are signifies solana files, right?
so
代表共享对象,也称为动态可重定位库或Cargo.toml中的dylib
。
What do we mean by cargo build-bpf?
BPF 是内核中的虚拟机,因此这应该指示 cargo 为该目标构建。
Is there any reason, why 2021 edition didn't work for the solana example?
我不知道,但我怀疑这是一个简单的修复。
Finally, why does the above command not output my .so file?
会不会是您缺少 Cargo.toml 中的 lib 部分:
[lib]
crate-type = ["cdylib", "lib"]
我试图通过自己重写 Rust 库来理解 solana/example-helloworld
。我已经这样做了,并从 package.json 文件生成了 .so
文件,以下是 运行:
cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program
我在上面使用是因为我已经在本地设置了 cargo 并且 运行 上面针对我的设置,我遇到了一些问题,从版本(使用 2021,不得不降级到 2018)到不得不重命名main.rs
到 lib.rs
和其他我不记得了。
下面是我在 Cargo.toml 文件所在的项目根目录中的终端的实际 运行ning 命令:
cargo build-bpf --manifest-path=./Cargo.toml --bpf-out-dir=dist/program
但是在运行ning上面,在dist目录下,什么都没有
这实际上是一个多层次的问题:
.so
文件是指 solana 文件,对吧?cargo build-bpf
是什么意思?- 为什么 2021 版不适用于 solana 示例,有什么原因吗?
- 最后,为什么上面的命令没有输出我的
.so
文件?
下面我的Cargo.toml:
[package]
name = "jjoek-sc"
version = "0.0.1"
description = "My first rust program for solana (hello john)"
authors = ["JJoek <info@jjoek.com>"]
license = "Apache-2.0"
homepage = "https://jjoek.com/"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
borsh = "0.9.1"
borsh-derive = "0.9.1"
solana-program = "~1.8.14"
下面是我的lib.rs
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint,
entrypoint::ProgramResult,
pubkey::Pubkey,
msg,
program_error::ProgramError,
};
/// Define the type of state stored in accounts
#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct GreetingAccount {
/// number of greetings
pub counter: u32,
}
// Declare and export the program's entrypoint
entrypoint!(process_instruction);
// Program entrypoint's implementation
pub fn process_instruction(program_id: &Pubkey, accounts: &[AccountInfo], _instruction_data: &[u8]) -> ProgramResult {
msg!("Hello, John everything is gonna be okay");
msg!("Hello World Rust program entrypoint");
// Iterating accounts is safer than indexing
let accounts_iter = &mut accounts.iter();
// Get the account to say hello to
let account = next_account_info(accounts_iter)?;
// The account must be owned by the program in order to modify its data
if account.owner != program_id {
msg!("Greeted account does not have the correct program id");
return Err(ProgramError::IncorrectProgramId);
}
// Increment and store the number of times the account has been greeted
let mut greeting_account = GreetingAccount::try_from_slice(&account.data.borrow())?;
greeting_account.counter += 1;
greeting_account.serialize(&mut &mut account.data.borrow_mut()[..])?;
msg!("Greeted {} time(s)!", greeting_account.counter);
Ok(())
}
.so file are signifies solana files, right?
so
代表共享对象,也称为动态可重定位库或Cargo.toml中的dylib
。
What do we mean by cargo build-bpf?
BPF 是内核中的虚拟机,因此这应该指示 cargo 为该目标构建。
Is there any reason, why 2021 edition didn't work for the solana example?
我不知道,但我怀疑这是一个简单的修复。
Finally, why does the above command not output my .so file?
会不会是您缺少 Cargo.toml 中的 lib 部分:
[lib]
crate-type = ["cdylib", "lib"]