Setting up gousb on Windows without pkg-config and Cygwin
/ 2 min read
Steps for setting up gousb
- Clone gousb in your project by running
git clone git@github.com:google/gousb
- One necessity to get it running is to install libusb on windows; which is not hard but gousb wants you to install the dev header as well with a pkg-config (.pc) file. To get past it, we can just download the package as it is by going to MSYS2 Packages [2] and searching for libusb. You’ll end up on this package [3] that has the archive which mingw installs. Just click on the download link in the second section.
- Use an un-archiving utility to un-archive this package and paste it in your project.
- Now edit the line which invokes pkg-config in gousb. It is located in
gosub/libusb.go
. Change#cgo pkg-config: libusb-1.0
to the expected output of pkg-config which is the CFLAGS and LDFLAGS. Something like –
- You might have to update the
#inlcude
line to the relative path as well in all the files. Just search for#include
and update all instances. - Now to make it work, you must tell your
go.mod
file to use the local package of gousb instead of the official one. You can do that by just adding a replace line in your mod file like –replace github.com/google/gousb => ./<relative-path-to-edited-gousb-project/s.
And you should be good to go.