- 1 year ago
How to install libusb-1.0 on Windows Mingw
To install libusb-1.0 on Windows using MinGW, you can follow these steps:
Download libusb: Visit the libusb GitHub repository releases page (https://github.com/libusb/libusb/releases) and download the latest stable release of libusb-1.0 for Windows in ZIP format.
Extract the ZIP Archive: Extract the contents of the downloaded ZIP archive to a directory of your choice.
Open MinGW Shell: Launch the MinGW Shell or any command prompt where you have MinGW configured and available in your PATH environment variable.
Navigate to libusb Directory: Use the
cd
command to navigate to the directory where you extracted the libusb files.Configure and Build: Run the following commands in the MinGW Shell to configure and build libusb:
bash./configure --disable-shared
make
This configures libusb with disabled shared libraries and then builds it using the
make
command.Install: After the build process completes, run the following command to install libusb:
bashmake install
This installs libusb to the default location on your system.
Verify Installation: To verify that libusb is installed correctly, you can compile and run a sample program. Save the following code to a file named
test.c
:c#include <stdio.h>
#include <libusb-1.0/libusb.h>
int main() {
libusb_context *context = NULL;
int r = libusb_init(&context);
if (r != LIBUSB_SUCCESS) {
printf("Failed to initialize libusb: %s\n", libusb_strerror(r));
return 1;
}
printf("libusb initialized successfully.\n");
libusb_exit(context);
return 0;
}
Then, compile and run the program using the following commands:
bashgcc -o test test.c -lusb-1.0
./test
If libusb is installed correctly, you should see the output "libusb initialized successfully."
That's it! You have now installed libusb-1.0 on Windows using MinGW. You can use libusb in your projects by linking against the libusb library (-lusb-1.0
) during the compilation process.