Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to generate .so file for solana deployment. (No errors)

Tags:

rust

solana

I am trying to understand the solana/example-helloworld by re-writing the rust lib myself. I have done this and from the package.json file, to generate the .so file, following is what is run:

cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program

I used above since I already have cargo setup locally and run above against my setup, I faced a few issues, from the edition (was using 2021, had to downgrade to 2018) to having to rename main.rs to lib.rs and others I can't remember. Below is my actual running command from the terminal in the project root directory where the Cargo.toml file is in:

cargo build-bpf --manifest-path=./Cargo.toml --bpf-out-dir=dist/program

But upon running above, in the dist directory, there is nothing

This is actually a multi-tied question:

  1. .so file are signifies solana files, right?
  2. What do we mean by cargo build-bpf?
  3. Is there any reason, why 2021 edition didn't work for the solana example?
  4. Finally, why does the above command not output my .so file?

My Cargo.toml below:

[package]
name = "jjoek-sc"
version = "0.0.1"
description = "My first rust program for solana (hello john)"
authors = ["JJoek <[email protected]>"]
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"

Below is my 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(())
}

like image 431
Johhn Avatar asked Oct 29 '25 13:10

Johhn


1 Answers

.so file are signifies solana files, right?

so stand for shared object, also known as a dynamically relocatable library or dylib in Cargo.toml.

What do we mean by cargo build-bpf?

BPF is a virtual machine inside the kernel, so this should instruct cargo to build for that target.

Is there any reason, why 2021 edition didn't work for the solana example?

I don't know, but I suspect it's a simple fix.

Finally, why does the above command not output my .so file?

Could it be that you are missing the lib section in Cargo.toml:

[lib]
crate-type = ["cdylib", "lib"] 
like image 102
hkBst Avatar answered Oct 31 '25 13:10

hkBst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!