Rust Error E0463: Can't Find Crate
E0463 means the compiler went looking for a whole crate (a library) and came back empty-handed. Usually your code has an extern crate line for a crate that isn’t in Cargo.toml. Sometimes the missing crate is std itself, which happens when you build for another kind of machine and haven’t installed that target yet. Both have quick fixes, and you don’t need to understand linkers to apply them. This page is part of the compiler errors guide.
The error message
Section titled “The error message”error[E0463]: can't find crate for `rand` --> src/main.rs:1:1 |1 | extern crate rand; | ^^^^^^^^^^^^^^^^^^ can't find crateThis is the program that produces it, in a fresh cargo new project with nothing under [dependencies]:
extern crate rand;
fn main() { let roll = rand::random_range(1..=6); println!("You rolled {roll}");}The second common form has no line number at all, because no line of your code asks for std. Every program needs it:
error[E0463]: can't find crate for `std` | = note: the `aarch64-unknown-linux-gnu` target may not be installed = help: consider downloading the target with `rustup target add aarch64-unknown-linux-gnu`You get that from cargo build --target aarch64-unknown-linux-gnu (64-bit ARM Linux, like a Raspberry Pi) when only your own machine’s target is installed. Which fix you need depends on the crate name and the note::
| What you see | What usually went wrong | Fix |
|---|---|---|
can't find crate for `rand` at an extern crate line |
the crate isn’t in Cargo.toml |
Fix 1 |
the same, in old code with #[macro_use] |
code written before the 2018 edition | Fix 2 |
can't find crate for `std` + target may not be installed |
building for a target rustup hasn’t downloaded | Fix 3 |
crate name using dashes are not valid next to E0463 |
a - in the crate name in your code |
Fix 4 |
What it means
Section titled “What it means”extern crate rand; tells the compiler “link the compiled library called rand into this program”. The compiler doesn’t download anything and doesn’t search the internet. It only looks at the libraries Cargo hands it, and Cargo only hands it the crates listed in Cargo.toml. No rand there means no rand library on the list, so E0463.
The std case is the same idea one level down. The standard library is also a compiled library, and rustup installs one copy per target. Your normal toolchain only has the copy for your own computer. Ask for an ARM build and the compiler looks for an ARM copy of std that isn’t there.
It’s like a recipe that says “use the flour from the cupboard”. If nobody bought flour, the cook can’t start, however good the recipe is.
Why Rust does this
Section titled “Why Rust does this”Rust has no global, shared folder of installed libraries like Python’s pip install or a system-wide node_modules. Each project says exactly what it uses in Cargo.toml, with versions, and Cargo builds those crates for that project. That’s why the same project builds the same way on your laptop, on a colleague’s machine and in CI. A crate that isn’t written down simply doesn’t exist for your code.
extern crate is mostly a leftover from Rust 2015. Since the 2018 edition, every crate in Cargo.toml is available automatically, so modern code just writes use rand::random_range;. You still meet extern crate in old tutorials and Stack Overflow answers, and that’s where most E0463s come from. Today, without the dependency, a use line gives E0432 and a path in your code gives E0433 instead. Same cause, different code.
See Cargo and crates for how dependencies work, and Rust tools for toolchains and targets.
How to fix it
Section titled “How to fix it”Fix 1: Add the crate with cargo add
Section titled “Fix 1: Add the crate with cargo add”Choose this when the missing crate is from crates.io, like rand, regex or serde_json. This is the most common case. Run this in the folder that contains Cargo.toml:
cargo add randCargo adds the newest version for you:
[dependencies]rand = "0.10.3"That alone fixes E0463. While you’re there, delete the extern crate rand; line; you don’t need it in edition 2018 or later (check edition = in Cargo.toml). This version prints a check instead of the roll, so the output is always the same:
fn main() { let roll = rand::random_range(1..=6); println!("Roll is between 1 and 6: {}", (1..=6).contains(&roll));}Output:
Roll is between 1 and 6: trueOld code may also call functions that changed between versions. If cargo add fixes E0463 but you then get E0425 or E0432 for something like thread_rng, check the crate’s docs for the version you have. See Adding a dependency with cargo add.
Fix 2: Replace old extern crate lines with use
Section titled “Fix 2: Replace old extern crate lines with use”Choose this when you copied pre-2018 code. It often starts with a block like this, and every line can give E0463:
#[macro_use]extern crate serde_derive;extern crate serde_json;
#[derive(Serialize)]struct Order { item: String, qty: u32,}error[E0463]: can't find crate for `serde_derive` --> src/main.rs:2:1 |2 | extern crate serde_derive; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
error[E0463]: can't find crate for `serde_json` --> src/main.rs:3:1 |3 | extern crate serde_json; | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crateDon’t add serde_derive as a separate crate. Today the derive macros come with serde when you turn on its derive feature:
cargo add serde --features derivecargo add serde_jsonThen delete the extern crate block and import what you use with a normal use line. #[macro_use] isn’t needed either:
use serde::Serialize;
#[derive(Serialize)]struct Order { item: String, qty: u32,}
fn main() { let order = Order { item: String::from("apple"), qty: 3 }; println!("{}", serde_json::to_string(&order).unwrap());}Output:
{"item":"apple","qty":3}If an extern crate line names a crate your code never actually uses, just delete the line. The JSON with serde lesson shows the modern setup in full.
Fix 3: Install the target with rustup target add
Section titled “Fix 3: Install the target with rustup target add”Choose this when the error is about std (or core) and the note: says the target may not be installed. Copy the target name from the help: line:
rustup target add aarch64-unknown-linux-gnurustup target list --installed # check what you have nowThen build again with the same --target. A target is the kind of machine you compile for, written as a “triple” like aarch64-unknown-linux-gnu or wasm32-unknown-unknown. rustup downloads the pre-built std for it, so the E0463 goes away.
Two notes. First, for many targets that’s not the last step: building a full program for another OS usually also needs a linker for that platform, which is a different error. Second, if the project has a rust-toolchain.toml, run the command inside the project folder, so rustup adds the target to the toolchain that project actually uses. See Components and targets and the WebAssembly lesson for a target you’ll likely use.
Fix 4: Write dashes as underscores in code
Section titled “Fix 4: Write dashes as underscores in code”Choose this when the crate’s name has a dash, like serde-json or tracing-subscriber. In Cargo.toml and on the command line the dash is fine. In Rust code, a - is a minus sign, so the name is always written with _. Old code with a dash gives this:
error: crate name using dashes are not valid in `extern crate` statements --> src/main.rs:1:14 |1 | extern crate serde-json; | ^^^^^^^^^^ dash-separated idents are not valid |help: if the original crate name uses dashes you need to use underscores in the code |1 - extern crate serde-json;1 + extern crate serde_json; |
error[E0463]: can't find crate for `serde_json`rustc already reads the name as serde_json, so the E0463 below it only appears when the crate is also missing from Cargo.toml. In a use line, a dash gives a different message, expected one of `::`, `;`, or `as`, found `-` . The fix is the same everywhere: cargo add the crate if needed, and write _ in code:
use serde_json::json;
fn main() { let order = json!({ "item": "apple", "qty": 3 }); println!("{order}");}Output:
{"item":"apple","qty":3}The same rule applies to your own package: a project named shop-app is imported as shop_app from its main.rs and its tests.
Where you’ll usually see it
Section titled “Where you’ll usually see it”Running rustc main.rs directly. rustc alone doesn’t read Cargo.toml, so even after cargo add rand, rustc --edition 2021 src/main.rs still says can't find crate for `rand` for an extern crate rand; line (and E0432 for a use rand::... line). Fix: build with cargo run or cargo build, which pass your dependencies to the compiler.
A crate listed under [dev-dependencies]. Dev-dependencies (added with cargo add --dev) only exist for tests, examples and benchmarks. Using one from normal code gives E0463 with extern crate, or E0433 with a path. Fix: move it to [dependencies] with cargo remove --dev serde_json and then cargo add serde_json.
Embedded boards without an operating system. For a target like thumbv7em-none-eabihf, installing it isn’t enough, because it has no std at all. The note changes to say so:
error[E0463]: can't find crate for `std` | = note: the `thumbv7em-none-eabihf` target may not support the standard library = note: `std` is required by `shop` because it does not declare `#![no_std]`Fix: write the program as #![no_std], which also means no println! and your own panic handler. The Embedded Rust Book walks you through it.
Related errors
Section titled “Related errors”- E0432:
unresolved import, what auseline gives when the crate is missing fromCargo.toml. - E0433:
failed to resolve, what a path likerand::rng()gives when the crate is missing. - E0603: the crate was found, but the item you want from it is private.
crate name using dashes are not valid: this one has no error code; write_instead of-(Fix 4).- All compiler errors: the full list of error pages.
Quick check
Section titled “Quick check”Quick check
1. Old code starts with extern crate regex; and you get E0463. What's the best fix in a 2021-edition project?
2. cargo build --target wasm32-unknown-unknown says it can't find crate for std and that the target may not be installed. What do you run?
3. Your Cargo.toml has tracing-subscriber = "0.3". How do you write the crate's name in Rust code?
Score: 0 / 3
Read more
Section titled “Read more”- E0463 — Rust error codes index: the official explanation of the missing-crate case.
- Increasing Functionality with a Crate — The Rust Book: adding your first dependency to
Cargo.toml, step by step. - Specifying Dependencies — The Cargo Book: versions, features, and the difference between
[dependencies]and[dev-dependencies]. - Path and module changes in Rust 2018 — Edition Guide: why
extern crateis no longer needed. - Cross-compilation — The rustup book: installing targets with
rustup target add.