-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
I am trying to build a #![no_std]
crate, but encountering the following error from the linker...
error: the `#[alloc_error_handler]` in this crate conflicts with allocation error handler in: std
error[E0152]: found duplicate lang item `panic_impl`
--> test/src/lib.rs:23:1
|
23 | fn panic(info: &PanicInfo) -> ! {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `std` (which `memchr` depends on)
= note: first definition in `std` loaded from /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libstd-bca906efb5fb081f.so, /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libstd-bca906efb5fb081f.rlib
= note: second definition in the local crate (`test2`)
error[E0152]: found duplicate lang item `eh_personality`
--> test/src/lib.rs:30:1
|
30 | extern "C" fn rust_eh_personality() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `std` (which `memchr` depends on)
= note: first definition in `std` loaded from /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libstd-bca906efb5fb081f.so, /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libstd-bca906efb5fb081f.rlib
= note: second definition in the local crate (`test2`)
For more information about this error, try `rustc --explain E0152`.
error: could not compile `test2` due to 3 previous errors
[cargo-make] ERROR - Error while executing command, exit code: 101
[cargo-make] WARN - Build Failed.
Even though my crate is no_std
, the linker is seemingly trying to link std
nonetheless (indeed if I comment out my implementations of the above functions in my crate, it links sucessfully). However, if a crate is marked no_std
, you wouldn't expect the std crate to be linked in no matter what, so this seems pretty odd?
Anyway, I then investigate the dependencies for my crate to see where memchr
is being included as a dependency. So as expected, it is included by cstr_core
from my Cargo.toml
. But also as a build dependency from bindgen
.
cstr_core = {version = "0.2.6", features = ["alloc"], default-features = false }
cargo tree --no-dedupe -p test2 -i memchr --target armv7-unknown-linux-gnueabihf -f "{p} # {f}"
memchr v2.5.0 # std
└── nom v7.1.3 # alloc,std
└── cexpr v0.6.0 #
└── bindgen v0.63.0 # default,log,logging,runtime,which,which-rustfmt
[build-dependencies]
└── test2 v0.1.0 (/home/share/git/test2/test2)
memchr v2.5.0 # std
└── cstr_core v0.2.6 # alloc
└── test2 v0.1.0 (/home/share/git/test2/test2)
However, cstr_core
should not include the std
feature of memchr (e.g. the std
feature should be required only at build time and not needed to be linked into the resulting binary). A similar project also linked against cstr_core
, but without using bindgen
shows no such depdendency?
cargo tree --no-dedupe -p test -i memchr --target armv7-unknown-linux-gnueabihf -f "{p} # {f}"
memchr v2.5.0 #
└── cstr_core v0.2.6 # alloc
└── test1 v0.1.0 (/home/share/git/test/test)
Have I mis-understood something?
$ rustc --version
rustc 1.68.0-nightly (c7572670a 2023-01-03)
$ cargo --version
cargo 1.68.0-nightly (2381cbdb4 2022-12-23)