我已安装libudev-dev
,我可以看到文件/usr/lib/x86_64-linux-gnu/libudev.so
但是当我运行gcc -Wall -ludev -o test test.c
时出现以下错误..
opensourcegeek@box:~/project/udev_device_discovery$ gcc -Wall -ludev -o test test.c
/tmp/ccg6Ydod.o: In function `main':
test.c:(.text+0xa): undefined reference to `udev_new'
test.c:(.text+0x35): undefined reference to `udev_enumerate_new'
test.c:(.text+0x4a): undefined reference to `udev_enumerate_add_match_subsystem'
test.c:(.text+0x60): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x76): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x82): undefined reference to `udev_enumerate_scan_devices'
test.c:(.text+0x8e): undefined reference to `udev_enumerate_get_list_entry'
test.c:(.text+0xab): undefined reference to `udev_list_entry_get_name'
test.c:(.text+0xc2): undefined reference to `udev_device_new_from_syspath'
test.c:(.text+0xd2): undefined reference to `udev_device_get_parent'
test.c:(.text+0xe2): undefined reference to `udev_device_get_devnode'
test.c:(.text+0x105): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x119): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x13f): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x153): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x179): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x197): undefined reference to `udev_device_unref'
test.c:(.text+0x1a3): undefined reference to `udev_list_entry_get_next'
test.c:(.text+0x1be): undefined reference to `udev_enumerate_unref'
test.c:(.text+0x1ca): undefined reference to `udev_unref'
test.c:(.text+0x1cf): undefined reference to `udev_new'
test.c:(.text+0x1fa): undefined reference to `udev_enumerate_new'
test.c:(.text+0x20f): undefined reference to `udev_enumerate_add_match_subsystem'
test.c:(.text+0x225): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x23b): undefined reference to `udev_enumerate_add_match_property'
test.c:(.text+0x247): undefined reference to `udev_enumerate_scan_devices'
test.c:(.text+0x253): undefined reference to `udev_enumerate_get_list_entry'
test.c:(.text+0x270): undefined reference to `udev_list_entry_get_name'
test.c:(.text+0x287): undefined reference to `udev_device_new_from_syspath'
test.c:(.text+0x297): undefined reference to `udev_device_get_devnode'
test.c:(.text+0x2ba): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x2ce): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x2f4): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x308): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x32e): undefined reference to `udev_device_get_sysattr_value'
test.c:(.text+0x34c): undefined reference to `udev_device_unref'
test.c:(.text+0x358): undefined reference to `udev_list_entry_get_next'
test.c:(.text+0x373): undefined reference to `udev_enumerate_unref'
test.c:(.text+0x37f): undefined reference to `udev_unref'
collect2: error: ld returned 1 exit status
我通常不会运行ubuntu,但是相同的代码适用于我的fedora(略微较旧版本的libudev)以及运行wheezy(较旧版本的libudev)的pi。
答案 0 :(得分:4)
顺序很重要,将库名放在编译/链接行的末尾:
$ gcc -Wall -o test test.c -ludev
答案 1 :(得分:2)
您看到的错误是链接器错误,而不是因为任何安装问题。将-ludev
移动到命令行选项的 end :
gcc -Wall -o test test.c -ludev