0

The following code results in "error[E0433]: failed to resolve: use of undeclared crate or module __client_accounts_test_common". I've seen other programs that use struct composition in this way and compile fine. Attempted changing the Anchor version, but it hasn't worked. Since the error comes from generated code I'm unsure the best way to proceed debugging. Any help appreciated :)

  • Anchor: 0.28.0
  • solana-cli 1.16.10 (src:382b3f16; feat:3712769919, client:SolanaLabs)
// instructions/mod.rs
pub mod test;
pub mod test_common;

pub use test::*;
pub use test_common::*;
// instructions/test_common.rs
use anchor_lang::prelude::*;

#[derive(Accounts)]
pub struct TestCommon<'info> {
    #[account(mut)]
    pub authority: Signer<'info>,
}
// instructions/test.rs
use anchor_lang::prelude::*;

use super::test_common::TestCommon;

#[derive(Accounts)]
pub struct Test<'info> {
  test_common: TestCommon<'info>
}

1 Answer 1

2

I looked at the code generated by the #[derive(Accounts)] macro from your example and I think the problem is that Anchor doesn't treat the case where you're using an Accounts item defined in a different file. It forgets to append crate:: when using the generated modules for that item.

To confirm this, if you add this line to your test.rs file, your code will compile fine: use crate::{__client_accounts_test_common, __cpi_client_accounts_test_common};

The solutions I can recommend:

  • define TestCommon in the same file as Test
  • or import everything from test_common not just TestCommon, so you'd use: use super::test_common::*;

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.