C语言 如何在 Mac OS X 上设置 libusb?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3853634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:36:43  来源:igfitidea点击:

How to set up libusb on Mac OS X?

cmacosmacportslibusb

提问by Dae

I'd like to try to make a user-space device driver using libusb on Mac, but I'm confused where to start. In the SDK installer (which I got from http://www.ellert.se/twain-sane) it said something about examples which I couldn't find anywhere on my computer.

我想尝试在 Mac 上使用 libusb 制作用户空间设备驱动程序,但我很困惑从哪里开始。在 SDK 安装程序(我从http://www.ellert.se/twain-sane 获得)中,它说了一些我在计算机上找不到任何示例的内容。

Could anyone please describe how do I set up libusb for development on OS X? May I use Xcode? What should I include in my code?

谁能描述一下我如何设置 libusb 以在 OS X 上进行开发?我可以使用 Xcode 吗?我应该在代码中包含什么?

采纳答案by spade78

I tried to install the SDK from the aforementioned website and couldn't find a trace of it once the installer finished. Though I did find some libusb items at /usr/local/Developer/SDKs/MacOSX10.6.sdk/usr/local/ I'm not sure it came from that installer as I couldn't find any examples, just libraries and they were labeled as libusb0.1.4.

我试图从上述网站安装 SDK,但在安装程序完成后找不到它的踪迹。虽然我确实在 /usr/local/Developer/SDKs/MacOSX10.6.sdk/usr/local/ 找到了一些 libusb 项目,但我不确定它来自那个安装程序,因为我找不到任何示例,只有库和它们被标记为 libusb0.1.4。

On the other hand, since you asked your question with the macports tag, I'd suggest you use that to install libusb as it at least puts everything in a known location:

另一方面,由于您使用 macports 标签问了您的问题,我建议您使用它来安装 libusb,因为它至少将所有内容放在一个已知位置:

  • /opt/local/var/macports/software for install files
  • /opt/local/lib for libraries
  • /opt/local/include for header files
  • /opt/local/var/macports/software 用于安装文件
  • /opt/local/lib 用于库
  • /opt/local/include 用于头文件

If you've never used macports then once you have macportsinstalled then you can install libusb using

如果您从未使用过 macports,那么一旦安装了macports,您就可以使用以下命令安装 libusb

sudo port install libusb

to install libusb1.0 or

安装 libusb1.0 或

sudo port install libusb-legacy

sudo port install libusb-legacy

to install libusb0.1.12.

安装 libusb0.1.12。

Then you can create a project in Xcode and link to the libusb-*.a library contained in /opt/local/lib (in my directory my library file is called libusb-1.0.a since I have libusb1.0 installed).

然后您可以在 Xcode 中创建一个项目并链接到包含在 /opt/local/lib 中的 libusb-*.a 库(在我的目录中,我的库文件名为 libusb-1.0.a,因为我安装了 libusb1.0)。

I don't have much experience using Xcode so I can't help you any further down this path. Personally what I've done so far is use a Python wrapper called pyusb to do some quick experimentation with libusb as I don't have to do IDE setup or library/include file setup with Python.

我没有太多使用 Xcode 的经验,所以我无法在这条道路上进一步帮助您。到目前为止,我个人所做的是使用名为 pyusb 的 Python 包装器对 libusb 进行一些快速实验,因为我不必使用 Python 进行 IDE 设置或库/包含文件设置。

UPDATE: Poking around the macports install directory for libusb, I didn't find any examples included which was a bummer. If you've gotten this far then I'd suggest going directly to the source for libusb, download and unpack the tar file, and building the code that's in the example directory. Sorry for the roundabout way of getting libusb examples but I've really come to appreciate the organization macports imposes on installations which saves me quite a bit of future pain (like when I want to uninstall).

更新:查看 libusb 的 macports 安装目录,我没有找到任何令人失望的示例。如果您已经做到了这一点,那么我建议您直接访问libusb的源代码,下载并解压 tar 文件,然后构建示例目录中的代码。对于获取 libusb 示例的迂回方式感到抱歉,但我真的很欣赏 macports 强加于安装的组织,这为我节省了很多未来的痛苦(比如我想卸载时)。

回答by Donald Derek

brew install libusb-compat 

Working on OSX Yosemite 10.10

在 OSX Yosemite 10.10 上工作

回答by dustinrwh

Easiest way to do this:

最简单的方法:

brew install libusb

Homebrewis amazing and I recommend it for all developers that use Mac.

Homebrew很棒,我向所有使用 Mac 的开发人员推荐它。