DEV Community

Prince Charles
Prince Charles

Posted on

FIx: 'Main thread Panicked at...' Error when compiling rust (.rs)

Initial Error: failed to run custom build command for hidapi v1.2.7

The Error experienced is unique to me and i didn't seem to see any solutions that helped, so after digging through the documentation i encountered a solution that helps and decided to write about it. I hope it helps you.

I encountered this error while compiling a rust program using the rust package manager

Terminal input
Current Os: Pop os
The terminal command
cargo install --git https://github.com/project-serum/anchor anchor-cli --locked

Following the error message, I traced the issue to a missing package not included in the dependecies: libudev

Traced Error:
--- stderr
thread 'main' panicked at 'Unable to find libudev: "pkg-config" "--libs" "--cflags" "libudev" did not exit successfully: exit status: 1
--- stderr

How to fix error

Type the command
sudo apt-get install libudev-dev

In your terminal navigate to the directory
cd /home/prince/.cargo/registry/src/github.com-1ecc6299db9ec823/hidapi-1.2.7/

open the file using
code Cargo.toml
or
nano Cargo.toml

Add the following code snippet and save
[dependencies]
libudev = "0.3"

Try to recompile the codebase. Hope this helps

Top comments (0)