So I am trying to get my binaries to work while allowing them to reference mods declared in the lib.rs file, only I can’t get them to work.
My cargo file:
[package]
name = "mytestapp"
version = "0.1.0"
edition = "2021"
[features]
mainnet = []
testnet = []
[[bin]]
name = "file1"
path = "src/standalone_tools/file1.rs"
[[bin]]
name = "file2"
path = "src/standalone_tools/file2.rs"
[[bin]]
name = "file3"
path = "src/standalone_tools/file3.rs"
[dependencies]
sha2 = "0.10"
My lib.rs
pub mod standalone_tools;
My main.rs
use mytestapp::standalone_tools::mod1;
use mytestapp::standalone_tools::mod2;
use mytestapp::standalone_tools::nod3;
main{
// stuff
}
Without the [[bin]] directives and files in the cargo, this will compile up to this point without errors.
My src/standalone_tools/file1.rs
use mytestapp::standalone_tools::mod1;
use mytestapp::standalone_tools::mod2;
use mytestapp::standalone_tools::mod3;
main{
// stuff
}
the file2 and file3 pretty much do the same thing.
This creates an error when using cargo build --features "mainnet"
All the src/standalone_tools/ files, end up erroring saying:
error[E0433]: failed to resolve: use of undeclared crate or module `mytestapp`
If instead of use mytestapp::standalone_tools::mod1;
I use use crate::standalone_tools::mod1;
the errors will change to
2 | use crate::standalone_tools::mod1;
| ^^^^^^^
| |
| unresolved import
| help: a similar path exists: `mytestapp::standalone_tools::mod1`
So none of my binaries compile.
If I remove all the [[bin]] declarations from the cargo file, the app will compile just fine, so using use mytestapp::standalone_tools::mod1;
for example, works from the main.rs and compiles perfectly.
So why can’t the binaries in src/standalone_tools find it? How do I make it so I can compile the binaries without having to restructure each binary into its own folder with its own cargo file? What I am doing wrong when trying to import the modules to the binaries?