Not possible to compile staticlib crate with no_std using stable compiler?

src/lib.rs:

#![no_std]

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

Cargo.toml:

[package]
name = "panic_test"
version = "0.1.0"
authors = ["..."]
edition = "2018"

[lib]
crate-type = ["staticlib"]

If you build this with the stable compiler (tried with 1.45.0) you'll see this error:

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

error: aborting due to previous error

error: could not compile `panic_test`.

However there's no way of adding eh_personality as that requires lang_items feature.

So it seems like there's no way of generating a static library form a no_std Rust crate using stable compiler. Am I missing anything?

See this section and the next in this blog for a longer explanation. Basically, you need to disable unwinding. I'm not sure if you can do that in a library though. It might only be possible in an executable.

2 Likes

panic = "abort" works for staticlibs.

2 Likes

Perfect, thanks all!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.