我正在使用Rust 1.35.0来尝试一些Rust示例,但我无法让它编译,因为我一直收到以下消息:
error[E0463]: can't find crate for `core`
我运行了rustc --explain E0463
,并看到以下消息:
You need to link your code to the relevant crate in order to be able to use it
(through Cargo or the `-L` option of rustc example). Plugins are crates as
well, and you link to them the same way.
这是我的货物。
[package]
name = "sensor-node"
version = "0.1.0"
authors = ["joesan <email@gmail.com>"]
edition = "2018"
[dependencies]
dwm1001 = "0.1.0"
panic-halt = "0.2.0"
nb = "0.1.1"
这是我的main.rs:
fn main() {
let s = String::from("hello"); // s comes into scope
takes_ownership(s); // s's value moves into the function...
// ... and so is no longer valid here
let x = 5; // x comes into scope
makes_copy(x); // x would move into the function,
// but i32 is Copy, so it’s okay to still
// use x afterward
} // Here, x goes out of scope, then s. But because s's value was moved, nothing
// special happens.
fn takes_ownership(some_string: String) { // some_string comes into scope
println!("{}", some_string);
} // Here, some_string goes out of scope and `drop` is called. The backing
// memory is freed.
fn makes_copy(some_integer: i32) { // some_integer comes into scope
println!("{}", some_integer);
} // Here, some_integer goes out of scope. Nothing special happens.
2条答案
按热度按时间oalqel3c1#
您的代码在Rust playground上运行良好,因此我建议检查您的Rust安装和环境设置。
您可能需要使用预配置的Rust Docker image来运行您的应用。安装Docker后,请:
转到项目文件夹并运行:
输出:
对于PC上的简单示例,您不需要以下任何依赖项:
下面是在Linux上测试示例的步骤:
打开
main.rs
,粘贴您的main.rs
样本并保存:在
hello
文件夹内的终端中,运行:而且输出很好:
这可能有助于:
输出:
输出:
t1rydlwq2#
当你第一次安装工具链时,rustup只安装你的主机平台的标准库--也就是你当前运行的架构和操作系统。要编译到其他平台,你必须安装其他目标平台。这可以通过rustup target add命令来完成。例如,要添加Android目标:
参见Rustup图书-交叉编译
例如:
要在目标计算机上获取目标字符串,如果安装了rust,可以运行:
例如输出
host
字段可用作rustup target add
的参数注意:您可能会遇到链接器问题,在这种情况下,您可以配置您的链接器,请参见Cargo Book - Configuration - Target