windows-kernel-rs icon indicating copy to clipboard operation
windows-kernel-rs copied to clipboard

Compiler gives an error "found duplicate lang item 'panic impl'

Open And329 opened this issue 1 year ago • 2 comments

I'm trying to compile code from this article (https://codentium.com/guides/windows-dev/windows-drivers-in-rust-safe-framework/), however it gives me the following error even tho #![no_std]. I tried using code from github and i face the same error

error[E0152]: found duplicate lang item panic_impl--> C:\Users\zen\Desktop\drv_new\windows-kernel-rs\src\lib.rs:45:1 | 45 | / fn panic(_info: &core::panic::PanicInfo) -> ! { 46 | | loop {} 47 | | } | |_^ | = note: the lang item is first defined in cratestd(whichbitflagsdepends on) = note: first definition instd loaded from \\?\C:\Users\zen\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd-ac24efe4baa6f4b5.rlib = note: second definition in the local crate (windows_kernel_rs`)

For more information about this error, try rustc --explain E0152.`

And329 avatar May 31 '24 09:05 And329

Any update?

jvsanchezo avatar Aug 09 '24 07:08 jvsanchezo

It appears that the root cause of this problem is the bitflags dependency used in windows-kernel-rs, which has dropped support for no_std starting from version 2.0. I encountered the same issue in my project, and resolved it by downgrading the bitflags dependency to version 1.3:

bitflags = "1.3"

Additionally, I had to comment out the derive attributes on line 9 of windows-kernel-rs/src/ioctl.rs to resolve the conflicts in deriving:

- #[derive(Clone, Copy, Debug, PartialEq, Eq)]
+ // #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RequiredAccess: u32 {
    const ANY_ACCESS = FILE_ANY_ACCESS;
    const READ_DATA = FILE_READ_DATA;
    const WRITE_DATA = FILE_WRITE_DATA;
    const READ_WRITE_DATA = FILE_READ_DATA | FILE_WRITE_DATA;
}

These changes allowed the project to compile successfully with no_std support.

ajaykumargdr avatar Nov 15 '24 13:11 ajaykumargdr