2
votes

Cargo.toml:

[package]
name = "proba"
version = "0.1.0"

[lib]
name = "mycoollib"
path = "src/mycoollib.rs"
crate-type = ["cdylib"]

src/mycoollib.rs:

#![no_std]

fn func(v: i32) -> i32 {
    v + 10
}

When I try to run cargo build:

error: language item required, but not found: `panic_fmt`
error: language item required, but not found: `eh_personality`

A nightly build is needed to implement panic_fmt and eh_personality, but "Using Rust Without the Standard Library" of the Rust book says that libs can build on stable.

1

1 Answers

2
votes

I believe that the documentation is misleading in this case. The problem is in the definition of the word "library".

A Rust library (sometimes known as an rlib) can use #[no_std] and not require definitions for panic_fmt or eh_personality. That's because eventually it will be linked against into a binary that does use the standard library, which defines these symbols.

A native library (either dylib, cdylib, or probably staticlib) has no guarantee of being linked with these symbols / language items, so they must be defined up front.

As you can see, both of these could be called a "library". I think that the book is being a little loose with the terminology, leading to the confusion.