Ошибка компиляции: не могу найти ящик для `core` - PullRequest
1 голос
/ 31 мая 2019

Я использую 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.

Вот мой Cargo.toml:

[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.

1 Ответ

1 голос
/ 31 мая 2019

Ваш код отлично работает на детской площадке Rust , поэтому я рекомендую проверить установку Rust и настройки среды.


Вы можете использовать предварительно сконфигурированный Rust Docker image для запуска вашего приложения. Установили Docker, тогда:

docker pull rust

Перейдите в папку вашего проекта и запустите:

docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp rust cargo run

Выход:

hello
5

Для вашего простого примера на ПК вам не нужны никакие из этих зависимостей:

[dependencies]
dwm1001 = "0.1.0"
panic-halt = "0.2.0"
nb = "0.1.1"

Вот мои шаги для тестирования вашего образца в Linux:

cargo new hello
cd hello
code .

Откройте main.rs и вставьте образец 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.

В терминале внутри папки hello введите:

cargo run

И вывод хороший:

hello
5

Это может помочь:

  1. Команда оболочки

    rustup component list --installed
    

    Выход:

    cargo-x86_64-unknown-linux-gnu
    clippy-x86_64-unknown-linux-gnu
    rls-x86_64-unknown-linux-gnu
    rust-analysis-x86_64-unknown-linux-gnu
    rust-docs-x86_64-unknown-linux-gnu
    rust-src
    rust-std-x86_64-unknown-linux-gnu
    rustc-x86_64-unknown-linux-gnu
    rustfmt-x86_64-unknown-linux-gnu
    
  2. Команда оболочки:

    rustup show
    

    Выход:

    Default host: x86_64-unknown-linux-gnu
    
    installed toolchains
    --------------------
    
    stable-x86_64-unknown-linux-gnu (default)
    nightly-x86_64-unknown-linux-gnu
    
    active toolchain
    ----------------
    
    stable-x86_64-unknown-linux-gnu (default)
    rustc 1.35.0 (3c235d560 2019-05-20)
    
...