目录
一、环境
二、问题
三、解决方法
一、环境
硬件:Jetson Xavier NX 套件
系统:Ubuntu?20.4
QT :QT5.12.9
二、问题
? ? ? ? 我在使用hidapi读写光机设备时,在将hidapi引入工程,进行编译时,提示大量的libusb方法undefined?reference 未找到。
:-1: error: hidapi.o: in function `hid_init':/projector/hidapi.c:499: error: undefined reference to `libusb_init' -1: error: hidapi.o: in function `hid_exit':/projector/hidapi.c:514: error: undefined reference to `libusb_exit' :-1: error: hidapi.o: in function `hid_enumerate':/projector/hidapi.c:535: error: undefined reference to `libusb_get_device_list' :-1: error:/projector/hidapi.c:544: undefined reference to `libusb_get_device_descriptor' :-1: error: /projector/hidapi.c:548: undefined reference to `libusb_get_active_config_descriptor' :-1: error: /projector/hidapi.c:550: undefined reference to `libusb_get_config_descriptor' :-1: error: /projector/hidapi.c:579: undefined reference to `libusb_open' :-1: error: /projector/hidapi.c:658: undefined reference to `libusb_close' :-1: error: /projector/hidapi.c:673: undefined reference to `libusb_free_config_descriptor' :-1: error: /projector/hidapi.c:677: undefined reference to `libusb_free_device_list' :-1: error: hidapi.o: in function `make_path': /projector/hidapi.c:484: error: undefined reference to `libusb_get_bus_number' :-1: error: /projector/hidapi.c:485: undefined reference to `libusb_get_device_address' :-1: error: linker command failed with exit code 1 (use -v to see invocation) ?
三、解决方法
在QT 工程中添加库引用? ?LIBS?+=?-lusb-1.0? 或?LIBS?+=?-lusb?即可,注意,libusb库 1.23版本以前的添加-lusb
unix:!macx {
LIBS += \
-lusb-1.0
}
重新清理、编译工程错误消失。
如果还是提示错误,请检查系统是否安装 libusb;在终端输入以下两条命令安装libusb库
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libusb-dev
参考:c++ - Libusb undefined reference to - Stack Overflow
OK!
? ? ? ? 至此,问题解决。
|