libusb 不会安装?



我正在尝试构建一个使用libusb的程序,我得到了很多错误,如

i2cbrdg.c:84: error: implicit declaration of function ‘usb_init’
i2cbrdg.c:88: error: implicit declaration of function ‘usb_find_busses’
i2cbrdg.c:89: error: implicit declaration of function ‘usb_find_devices’
i2cbrdg.c:90: error: implicit declaration of function ‘usb_get_busses’

所以我正在尝试安装libusb,但是这样做有麻烦。我已经安装了libusb-dev,这似乎是好的。当我执行dpkg -L lib -dev时,我得到一个目录列表。然而,当我dpkg -L libusb时,我得到

Package `libusb' is not installed.
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

我已经执行sudo apt-get install libusb-1.0并且运行正常。当我尝试再次执行时,我得到消息

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libusb-1.0-0' for regex 'libusb-1.0'
Note, selecting 'libusb-1.0-0-dev' for regex 'libusb-1.0'
libusb-1.0-0-dev is already the newest version.
libusb-1.0-0 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

我也试过用yum安装它,它仍然说它没有安装。我已经下载了包的tar并在上面运行make,这似乎也没问题(没有显式的错误消息)。我真的不知道下一步该尝试什么。dpkg消息一直告诉我它没有安装。谁能告诉我进去的方向?

库libusb 0.1和libusb 1.0非常不同。您现在应该决定要使用哪一个。我推荐libusb 1.0。上次我检查的时候,libusb-devlibusb包安装libusb 0.1,而libusb-1.0-0-dev包应该安装libusb 1.0,至少在Ubuntu中。

在您安装所需的库之后,您将需要在C文件中#include头文件,并添加正确的链接器选项。

对于libusb 1.0, include语句应该是

#include <libusb-1.0/libusb.h>

,链接器选项是

-lusb-1.0

最新更新