Search code examples
linuxlinux-kernelgcc-warningudev

udevadm code with undefined reference error


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.


Solution

  • 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).