This a simple project to demonstrate how to include libusb library in C++ using cmake without relying on -lusb-1.0 or -lusb flags.
libusb is a library for USB device access from Linux, macOS, Windows, OpenBSD/NetBSD, Haiku, Solaris userspace, and WebAssembly via WebUSB. It is written in C (Haiku backend in C++).
This project contain the libusb library precompiled for Linux and Windows.
libusb homepage: http://libusb.info/
To use this library you need to have knowledge of how to operate USB devices from a software standpoint (descriptors, configurations, interfaces, endpoints, control/bulk/interrupt/isochronous transfers, etc).
Full information can be found in the USB 3.0 Specification which is available for free download. You can probably find less verbose introductions by searching the web.
mkdir build
cd build
cmake ../
cmake --build .
If compiling is success you will find executable in:
For Windows: build\Debug\main.exe
For Linux: build\main
For Windows:
cd build\Debug main.exe
For Linux:
cd build ./main
Total USB devices found: 7
Vendor:Device = 8087:8000
Vendor:Device = 1d6b:0002
Vendor:Device = 8087:8008
Vendor:Device = 1d6b:0002
Vendor:Device = 1d6b:0003
Vendor:Device = 062a:4c01
Vendor:Device = 1d6b:0002
If you get something like the above then everything is working fine.
Now you can start adding your own code and build stuff.
- Cmake
Minimum required VERSION 3.10
- Windows SDK Platform Tools
If you're using windows