0

udevadm executes well on my desktop. However, I have written the code which links to libudev.so, by compiling my code with the following command:

gcc -g -Wall -ludev test.c -o testadm

I got a bunch of errors in the following log:

undefined reference to udev_monitor_receive_device

undefined reference to udev_device_unref

undefined reference to udev_monitor_get_fd

undefined reference to udev_monitor_get_fd

.......

I think the libudev.so lives in /lib/x86_64-linux-gnu/ could already be linked well.

Please provide feedback.

Sam
  • 4,521
  • 13
  • 46
  • 81

1 Answers1

2

I think gcc didn't find libudev. Find where it lives and pass the path to gcc with -L option like

gcc -g -Wall -L/lib/crazylibs -ludev test.c -o testadm

If you can't find you might missing devel version like libudev-devel (dunno your distro).

Alexander Dzyoba
  • 4,009
  • 1
  • 24
  • 29
  • I have Ubuntu 12.04 and 12.10 on my desktop. By running this gcc -g -Wall -L/lib/libudev.so.0.13.0 -ludev test.c -o testadm, I still got the same undefined reference. – Sam Apr 11 '14 at 08:21
  • In Ubuntu, I think libudev-dev equals to libudev-devel, I have also installed this onto my desktop but errors still appeared. – Sam Apr 11 '14 at 08:31
  • `-L` is **path** to your libraries, where you have to have `libudev.so`. Try to create symbolic link `libudev.so` to `libudev.so.0.13.0`. Also, /lib is default path for libraries search so you don't have to pass it with -L. Try symbolic link. – Alexander Dzyoba Apr 11 '14 at 08:50
  • gcc -g -Wall /lib/x86_64-linux-gnu/libudev.so.0.13.0 -ludev testadm.c -o testadm <-----This is what I tried on my desktop. – Sam Apr 11 '14 at 08:55
  • Thanks AVD. I just figured out the problem. It's weird that when I use gcc 4.6, the error keeps appearing. However, When I tried gcc 4.4, it works and the executable runs well. I have no idea about why this happens but it's finally resolved. Thanks for your feedback. – Sam Apr 11 '14 at 09:20
  • Strange:-/ Glad to help you. – Alexander Dzyoba Apr 11 '14 at 09:27