英文:
Working with USB in Go
问题
有人可以提供一个使用go-libusb
(或者其他在Golang中与USB一起工作的库)的示例吗?
- 我已经创建了
libusb
包。 - 从https://github.com/popons/go-libusb/blob/main/libusb.go复制了内容。
出现了一个错误:
未解析的符号:'_Cstruct_usb_device_descriptor'
谢谢。
英文:
Can somebody provide an example of using go-libusb
(or may be any other lib working with USB in Golang) .
- I have created package
libusb
- Copied the content from https://github.com/popons/go-libusb/blob/main/libusb.go
There is an error:
Unresolved symbol: '_Cstruct_usb_device_descriptor'
Thank you.
答案1
得分: 3
首先,你需要从http://www.libusb.org/wiki/libusb-win32安装libusb,然后将// #include<usb.h>
更改为:
/*
#cgo LDFLAGS: -lusb
#include <usb.h>
*/
将descriptor _Cstruct_usb_device_descriptor
更改为descriptor C.struct_usb_device_descriptor
。
或者从https://github.com/OneOfOne/go-libusb拉取我的分支,我已经发送了一个带有更改的拉取请求。
英文:
First you have to install libusb from http://www.libusb.org/wiki/libusb-win32, then either change // #include<usb.h>
to:
/*
#cgo LDFLAGS: -lusb
#include <usb.h>
*/
And descriptor _Cstruct_usb_device_descriptor
to descriptor C.struct_usb_device_descriptor
.
Or pull my fork from https://github.com/OneOfOne/go-libusb, I already sent a pull request with the changes.
答案2
得分: 3
go-libusb包是由popons开发的一个对libusb-0.1基于C语言的USB驱动程序的封装。libusb-0.1已经被宣布为“废弃且不再维护”。[来源:libusb API版本概述]
如果要在Go中使用USB,我建议使用一个libusb 1.0(GitHub上的源代码),例如:
上述两个Go驱动程序都需要安装C版本的libusb。在Windows上安装,请参考libusb Windows驱动程序安装说明,该说明建议使用Zadig。你也可以查看SO问题在Windows 7上安装libusb-1.0,但唯一的答案似乎只展示了如何安装libusb-0.1而不是libusb-1.0。
作为Windows用户,我知道这对你没有帮助,但对于OS X用户,可以使用Homebrew来安装libusb:
$ brew install libusb
英文:
The go-libusb package by popons is a wrapper for the libusb-0.1 C-based USB driver. libusb-0.1 is "deprecated and unmaintained." [Source: libusb API version overview]
For using USB with Go, I'd recommend using a libusb 1.0 (source on GitHub) Go-driver, such as:
- gousb — Originally created by Kyle Lemons. There are newer forks, such as the one by truveris.
- libusb — Discloure: I'm the original creator.
Both of the above Go drivers require having the C-version of libusb installed. To install on Windows, take a look at the libusb Windows driver installation instructions, which recommend using Zadig. You could also look at the SO question Installing libusb-1.0 on Windows 7, but the only answer appears to show how to install libusb-0.1 not libusb-1.0.
As a Windows user, I know this doesn't help you, but for OS X users, libusb can be installed using Homebrew:
$ brew install libusb
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论