Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何修复Ubuntu 15上libudev的链接器错误_C_Linux_Ld_Udev_Ubuntu 15.10 - Fatal编程技术网

C 如何修复Ubuntu 15上libudev的链接器错误

C 如何修复Ubuntu 15上libudev的链接器错误,c,linux,ld,udev,ubuntu-15.10,C,Linux,Ld,Udev,Ubuntu 15.10,我已经安装了libudev dev,我可以看到文件/usr/lib/x86\u 64-linux-gnu/libudev.so,但是当我运行gcc-Wall-ludev-o 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): undef

我已经安装了
libudev dev
,我可以看到文件
/usr/lib/x86\u 64-linux-gnu/libudev.so
,但是当我运行
gcc-Wall-ludev-o 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上也可以运行相同的代码

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

gcc -Wall -o test test.c -ludev

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

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

gcc-Wall test.c-ludev试试这个或gcc-std=c99 test.c-ludev好奇,为什么fedora或wheezy可以容忍错误的顺序?@opensourcegeek您在fedora上的顺序是正确的,或者是两次:
gcc-Wall-ludev-o test test.c-ludev
(或者您将其作为Makefile的一部分?)。否则,GNU ld也会在那里抱怨。@l3x看起来不像,我已经在命令行上直接尝试过了
gcc-Wall-ludev-o test test.c
它在fedora(gcc 4.8.2-7)和哮喘病(gcc 4.6.3)上运行良好。