1

I create a Solana native program that is being compiled successfully but then I import that program in a rust crate and use that crate in other program in anchor program but I'm getting this error

 /usr/bin/ld: /home/dev-ice/bitoku/bitoku-user-sample/target/debug/deps/libbitoku_sdk_agent_native-82a6d751ee4c4264.rlib(bitoku_sdk_agent_native-82a6d751ee4c4264.bitoku_sdk_agent_native.d62308ee-cgu.15.rcgu.o): in function `entrypoint':
          /home/dev-ice/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-program-1.14.13/src/entrypoint.rs:126: multiple definition of `entrypoint'; /home/dev-ice/bitoku/bitoku-user-sample/target/debug/deps/sample_program.1iglnqtogkpe73be.rcgu.o:/home/dev-ice/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-program-1.14.13/src/entrypoint.rs:126: first defined here
          collect2: error: ld returned 1 exit status

so the entrypoint of the solana program is conflicting with the entrypoint of my program. But that program is being comipiled and run successfully!

here's cargo.toml for the native porgram

[package]
name = "bitoku-sdk-agent-native"
version = "0.1.8"
edition = "2021"
description = "bitoku-sdk-agnet program"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
no-entrypoint = []

[dependencies]
solana-program = {version="1.14.13", features =["no-entrypoint"] }
borsh = "0.9"
thiserror = "1.0.20"

[lib]
crate-type = ["cdylib", "lib"]

cargo.toml for the intermediate crate

[package]
name = "bitoku-sdk"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
solana-program = "1.13.5"
bitoku-sdk-agent-native = {version = "0.1.9", features=["no-entrypoint"]}

and cargo.toml for the anchor program that is throwing the error

[package]
name = "sample-program"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "sample_program"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.26.0"
bitoku-sdk =    {path = "../../../bitoku-sdk",version="0.1.0"}

Update : I tried this in a fresh anchor program and I got this, which I was getting previously as well

the `#[global_allocator]` in this crate conflicts with global allocator in: bitoku_sdk_agent_native

error: could not compile `hello` due to previous error

but there is no global allocator like from std::alloc

this is the program that is throwing this error

use anchor_lang::prelude::*;
use bitoku_sdk::*;

// const MAX_ENTRY_LEN: usize = 1_000_000;

declare_id!("EjLMs3HBGWxEpzF7yGQTuDwjiNcagYTt4D6pWt7oPqM4");

#[program]
pub mod sample_program {
    use super::*;

    //This function will register a diary client.
    pub fn init_diary(ctx: Context<InitDiary>) -> Result<()> {
        //sdk agent logic

        let accounts = &CpiAccounts {
            fee_payer: ctx.accounts.owner.to_account_info(),
            bookkeeper: ctx.accounts.bookkeeper.to_account_info(),
            system_program: ctx.accounts.system_program.to_account_info(),
            bitoku_agent_program_id: ctx.accounts.agent.to_account_info(),
            request: ctx.accounts.request.to_account_info(),
            sys_var_program: ctx.accounts.rent.to_account_info(),
        };

        let my_id = reg_client(accounts);

        //actual program logic
        ctx.accounts.diary.owner = *ctx.accounts.owner.key;
        ctx.accounts.diary.last_update = ctx.accounts.clock.unix_timestamp;
        ctx.accounts.diary.bitoku_client_id = my_id;

        Ok(())
    }

    pub fn add_entry(ctx: Context<AddEntry>, diary_content: String) -> Result<()> {
        //sdk logic
        let accounts = &CpiAccounts {
            fee_payer: ctx.accounts.owner.to_account_info(),
            bookkeeper: ctx.accounts.bookkeeper.to_account_info(),
            request: ctx.accounts.request.to_account_info(),
            system_program: ctx.accounts.system_program.to_account_info(),
            sys_var_program: ctx.accounts.rent.to_account_info(),
            bitoku_agent_program_id: ctx.accounts.agent.to_account_info(),
        };

        // Actual program logic

        let mut arr: [u8; 1024] = [0; 1024];
        let bytes = diary_content.as_bytes();
        arr[..bytes.len()].copy_from_slice(bytes);

        let file_name = "diary".to_string();

        write_file(&accounts, &file_name, arr, 1);

        ctx.accounts.diary.last_update = ctx.accounts.clock.unix_timestamp;
        ctx.accounts.diary.num_entries += 1;

        Ok(())
    }
}

#[derive(Accounts)]
pub struct InitDiary<'info> {
    #[account(mut)]
    owner: Signer<'info>,

    #[account(
        init,
        payer= owner,
        space= 8+32+1+8+4,
        seeds= ["diary".as_ref(), owner.key().as_ref()],
        bump
    )]
    diary: Account<'info, DiaryDescriptor>,

    ///CHECK
    #[account(
        mut,
        seeds =["book_keeper".as_bytes()],
        seeds::program=agent,
        bump
     )]
    bookkeeper: UncheckedAccount<'info>,
    ///CHECK
    #[account(
        mut,
        seeds = [
            "request".as_bytes(),
            owner.key().as_ref(),
        ],
        seeds::program=agent,
        bump
    )]
    request: UncheckedAccount<'info>,
    ///CHECK
    agent: UncheckedAccount<'info>,

    clock: Sysvar<'info, Clock>,

    system_program: Program<'info, System>,

    rent: Sysvar<'info, Rent>,
}

#[derive(Accounts)]
pub struct AddEntry<'info> {
    owner: Signer<'info>,

    ///CHECK
    #[account(
        mut,
        seeds =["book_keeper".as_bytes()],
        seeds::program=agent,
        bump
     )]
    bookkeeper: UncheckedAccount<'info>,
    ///CHECK
    agent: UncheckedAccount<'info>,

    #[account(
        mut,
        seeds = ["diary".as_bytes(),owner.key().as_ref()],
        bump
    )]
    diary: Account<'info, DiaryDescriptor>,

    ///CHECK
    #[account(
        mut,
        seeds = [
            "request".as_bytes(),
            owner.key().as_ref(),
        ],
        seeds::program=agent,
        bump
    )]
    request: UncheckedAccount<'info>,

    clock: Sysvar<'info, Clock>,

    system_program: Program<'info, System>,

    rent: Sysvar<'info, Rent>,
}

#[account]
pub struct DiaryDescriptor {
    owner: Pubkey,
    bitoku_client_id: u8,
    last_update: i64,
    num_entries: u32,
}


2 Answers 2

3

You probably need to add the no-entrypoint feature to your imported crate.

bitoku-sdk = {path = "../../../bitoku-sdk", features = ["no-entrypoint"]}

1
  • already done that, no difference Commented Jan 31, 2023 at 12:02
1

Apparently, I had to add this line #[cfg(not(feature = "no-entrypoint"))] in the lib.rs of the native-program

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.