Compilation error: can't find crate for `core`

10,612

Your code works fine on the Rust playground, so I recommend checking your Rust installation and environment settings.


You may want to use the preconfigured Rust Docker image to run your app. Have Docker installed, then:

docker pull rust

Go to your project folder and run:

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

Output:

hello
5

For your simple example on a PC, you don't need any of these dependencies:

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

Here are my steps to test your sample on Linux:

cargo new hello
cd hello
code .

Open main.rs and paste your sample main.rs and save:

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.

In a terminal inside the hello folder, run:

cargo run

And the output is good:

hello
5

This may help:

  1. Shell command

    rustup component list --installed
    

    Output:

    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. Shell command:

    rustup show
    

    Output:

    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)
    
Share:
10,612
joesan
Author by

joesan

Enduro with Trek Remedy 8.... Flowing along with the trail....

Updated on June 11, 2022

Comments

  • joesan
    joesan almost 2 years

    I'm using Rust 1.35.0 to try out some Rust examples and I could not get it to compile, as I keep getting the following message:

    error[E0463]: can't find crate for `core`
    

    I ran rustc --explain E0463 and I see the following message:

    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.
    

    Here is my Cargo.toml:

    [package]
    name = "sensor-node"
    version = "0.1.0"
    authors = ["joesan <[email protected]>"]
    edition = "2018"
    
    [dependencies]
    dwm1001 = "0.1.0"
    panic-halt = "0.2.0"
    nb = "0.1.1"
    

    Here is my 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.
    
  • joesan
    joesan almost 5 years
    The reason why I have those dependencies is to do something else, but since I'm starting out with Rust, I wanted to test ownership concepts first! So I do need those dependencies!
  • wasmup
    wasmup almost 5 years
    OK, with these extra dependencies present, the cargo run still runs OK, but takes more time.
  • wasmup
    wasmup almost 5 years
    May be clean install of rust may solve the problem. (It seems)
  • joesan
    joesan almost 5 years
    rustup self uninstall - Will try this and then do a fresh install to see if it works!
  • wasmup
    wasmup almost 5 years
    Your code also works fine (press Run) on the rust playground.
  • joesan
    joesan almost 5 years
    How can I change the default host for this specific project? Right now, my default host is: x86_64-apple-darwin which I guess is why I get this error
  • wasmup
    wasmup almost 5 years
    Use rustup target help to get help. and use rustup target list to get list of installed and available targets, use rustup toolchain help and rustup toolchain list. see here.
  • chovy
    chovy almost 2 years
    I still have this issue on Linux
  • wasmup
    wasmup almost 2 years
    @chovy: check this and this
  • chovy
    chovy almost 2 years
    2nd link i already tried. I get this error: ` = note: /usr/bin/ld:/tmp/rustcPJoEQl/list:6: syntax error in VERSION script collect2: error: ld returned 1 exit status`
  • wasmup
    wasmup almost 2 years
    @chovy see this. Is your code working in the Rust playground?
  • chovy
    chovy almost 2 years
    I don’t really know anything about rust. Just trying to get a dfinity canister working.
  • wasmup
    wasmup almost 2 years
    @chovy: How about this?