ubuntu在线安装libusb
作者:互联网
- 在线安装命令
-
1.安装命令: Ubuntu 测试 其他linux应该是一样的 sudo apt-get install libusb-1.0-0-dev sudo apt-get install libusb-dev
- 编译命令
-
libusb库 1.23 之前(应该是的 1.23之前没有做测试) 例1.gcc -o main main.c -lusb libusb库 1.23 之后 例2.gcc -o main main.c -lusb-1.0
- 问题及测试程序 点击访问
-
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <libusb-1.0/libusb.h> #include <stdio.h> #include <sys/types.h> static void print_devs(libusb_device **devs) { libusb_device *dev; int i = 0; while ((dev = devs[i++]) != NULL) { struct libusb_device_descriptor desc; int r = libusb_get_device_descriptor(dev, &desc); if (r < 0) { fprintf(stderr, "failed to get device descriptor"); return; } printf("%04x:%04x (bus %d, device %d)\n", desc.idVendor, desc.idProduct, libusb_get_bus_number(dev), libusb_get_device_address(dev)); } } int main(void) { libusb_device **devs; int r; ssize_t cnt; r = libusb_init(NULL); if (r < 0) return r; cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) return (int) cnt; print_devs(devs); libusb_free_device_list(devs, 1); libusb_exit(NULL); return 0; }
标签:在线,get,dev,devs,libusb,ubuntu,device,include 来源: https://blog.csdn.net/Britripe/article/details/110110165