.../rust/
我使用此链接开始使用工具:
https://medium.com/@wizofe/cross-compiling-rust-for-arm-e-g-raspberry-pi-using-any-os-11711ebfc52b
-
cargo new --bin rust_test
. 这就产生了
.../rust/rust_test
.
-
cargo build
或
cargo build --target=armv7-unknown-linux-gnueabihf
(给我的小猎犬)
到现在为止,一直都还不错。现在我想创建一个可以与其他项目共享的库。但我会在rust_test文件夹中创建它
.../rust/rust_test/utils
:
-
创建库时使用:
cargo new --lib utils
-
我可以在
utils
货物建造
-
现在我想让我的rust_测试项目作为一个依赖项来构建它,我发现我只需要添加:
utils = { path = "utils" }
我的rust_test.toml文件。
-
货物建造
再说一遍,到目前为止一切都很好。对我来说,难题的最后一部分是在utils库中使用函数。里面有两个功能。一个叫
adder(a,b)
test123()
. 这就是我被困的地方。公式化这些函数的语法似乎都不正确。
以下是我的主要文件:
锈蚀试验
.../rust/rust_test/
货物.toml
[package]
name = "rust_test"
version = "0.1.0"
authors = ["adadachanji@gmail.com <adadachanji@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
utils = { path = "utils" }
mod utils;
fn main() {
println!("Hello, world!");
utils::test123(); // ??? - does not work
}
实用工具
.../rust/rust_test/utils/
货物.toml
[package]
name = "utils"
version = "0.1.0"
authors = ["adadachanji@gmail.com <adadachanji@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
图书馆
#[cfg(test)]
mod tests {
#[test]
fn adder<T>(a: T, b: T) -> T {
return a + b;
}
}
#[cfg(utils)]
mod utils {
#[utils]
fn test123() {
println!("test!");
}
}
输出
~/bbb/development/rust/rust_test$ cargo build
Compiling rust_test v0.1.0 (/home/user/bbb/development/rust_test)
error[E0583]: file not found for module `utils`
--> src/main.rs:1:1
|
1 | mod utils;
| ^^^^^^^^^^
|
= help: to create the module `utils`, create file "src/utils.rs"
error[E0425]: cannot find function `test123` in module `utils`
--> src/main.rs:6:12
|
6 | utils::test123(); // ??? - does not work
| ^^^^^^^ not found in `utils`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0425, E0583.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `rust_test`.
#[cfg...]
#[...]
行不行。但从我所读到的我认为
mod utils;
也许我还没有链接这些文件-我只是建立了它们?
所以问题是我现在需要做什么来将我的库链接到我的应用程序,这样我就可以使用lib函数了
?
更新
mod utils公司;
user@user-VirtualBox:~/bbb/development/rust/rust_test$ cargo build
Compiling rust_test v0.1.0 (/home/user/bbb/development/rust_test)
error[E0425]: cannot find function `test123` in crate `utils`
--> src/main.rs:4:12
|
4 | utils::test123(); // ??? - does not work
| ^^^^^^^ not found in `utils`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.
error: could not compile `rust_test`.