简体   繁体   中英

How to fix linker errors for libudev on Ubuntu 15

I've installed libudev-dev , I can see the file /usr/lib/x86_64-linux-gnu/libudev.so but when I run gcc -Wall -ludev -o test test.c I get following error..

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

I don't usually run ubuntu, but same code works on my fedora(slightly older version of libudev) and also a pi which runs wheezy (older version of libudev).

顺序很重要,将库名放在编译/链接行的末尾:

$ gcc -Wall -o test test.c -ludev

您看到的错误是链接器错误,而不是因为任何安装问题。将-ludev移动到命令行选项的末尾

gcc -Wall -o test test.c -ludev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM