1

I am building a Rust project and whenever I try to build I get

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "`\"pkg-config\" \"--libs\" \"--cflags\" \"libudev\"` did not exi
t successfully: exit status: 1\nerror: could not find system library 'libudev' required by the 'libudev-sys' crate\n\n--- stderr\nPackage l
ibudev was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libudev.pc'\nto the PKG_CONFIG_PATH e
nvironment variable\nNo package 'libudev' found\n"', /home/nikola/.cargo/registry/src/github.com-1ecc6299db9ec823/libudev-sys-0.1.4/build.r
s:38:41

Its clear enough of an error message, but the issue is, all that I could find online, 10+ solutions mention installing pkg-config and libudev-dev. I have both installed and reinstalled but I dont have the libudev.pc file

Running apt search udev gives these entries

librust-libudev-sys-dev/focal 0.1.4-1 amd64
  FFI bindings to libudev - Rust source code

libu2f-udev/focal,focal,now 1.1.10-1 all [installed]
  Universal 2nd Factor (U2F) common files

libudev-dev/focal-updates,now 245.4-4ubuntu3.17 amd64 [installed]
  libudev development files

libudev1/focal-updates,now 245.4-4ubuntu3.17 amd64 [installed,automatic]
  libudev shared library

Missing the libudev.pc

➜  ~project git:(master) ✗ locate libudev.pc                     
➜  ~project git:(master) ✗ 
➜  ~pkgconfig: echo $PKG_CONFIG_PATH                    

➜  ~pkgconfig: 
Sir Isaac
  • 13
  • 2
  • [The `libudev-dev` package you have](http://launchpadlibrarian.net/598347573/libudev-dev_245.4-4ubuntu3.17_amd64.deb) does include `libudev.pc`, are you sure it’s not present in `/usr/lib/x86_64-linux-gnu/pkgconfig/`? – Stephen Kitt Aug 28 '22 at 12:43
  • @StephenKitt yeah, I found it there, unfortunately the other answers listed different locations and the locate package returning nothing threw me off. Thank you – Sir Isaac Aug 28 '22 at 12:53
  • That path should be in `pkg-config`’s default search path on your system, so it’s rather surprising that `pkg-config --libs --cflags libudev` doesn’t work. What does `pkg-config --variable pc_path pkg-config` show? – Stephen Kitt Aug 28 '22 at 14:10
  • This is the result `/home/linuxbrew/.linuxbrew/lib/pkgconfig:/home/linuxbrew/.linuxbrew/share/pkgconfig:/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/os/linux/pkgconfig` Only brew, not sure why. But now that I added the path you provided me into the config path its working as intended – Sir Isaac Aug 28 '22 at 15:47

2 Answers2

0

Try this:

echo 'export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/"' >> $HOME/.bashrc

EDIT: forgot to mention that you'll have to either close and reopen any open terminals or execute source $HOME/.bashrc in the current terminal for the changes to have effect.

telometto
  • 1,825
  • 2
  • 8
  • 29
0

You’re using pkg-config from Homebrew, and that only knows about Homebrew-packaged libraries by default.

On Ubuntu, if you intend to develop with Ubuntu-provided packages such as libudev-dev, you should really use the Ubuntu-provided pkg-config: uninstall the Homebrew version, and install pkg-config using apt.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Yeah I will probably have to do that, will that affect my system if I delete it and reinstall it? I honestly dont remember even downloading it from Brew in the first place – Sir Isaac Aug 30 '22 at 10:36
  • Deleting it (using Brew) and re-installing it (using `apt`) won’t affect your system. It might affect Brew dependencies however (perhaps that’s how it got installed). – Stephen Kitt Aug 30 '22 at 10:41