How to set up libusb on Mac OS X?
Asked Answered
R

4

43

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.

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?

Resurrection answered 4/10, 2010 at 8:25 Comment(0)
C
17

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.

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:

  • /opt/local/var/macports/software for install files
  • /opt/local/lib for libraries
  • /opt/local/include for header files

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

sudo port install libusb

to install libusb1.0 or

sudo port install libusb-legacy

to install 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).

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.

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).

Claytor answered 13/10, 2010 at 16:26 Comment(3)
Even better, install with Homebrew: "brew install libusb".Lightish
@louielouie: Why is that better?Intrust
@JonCage because this answer is from 2010. A lot has changed in five years. Homebrew is the best package manager for OS X at this time.Billmyre
M
66
brew install libusb-compat 

Working on OSX Yosemite 10.10

Mckeehan answered 3/12, 2014 at 6:5 Comment(1)
This answer is more appropriate for these days, in which brew is the standard way to install these things!Itinerate
W
19

Easiest way to do this:

brew install libusb

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

Warrior answered 25/8, 2017 at 15:53 Comment(0)
C
17

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.

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:

  • /opt/local/var/macports/software for install files
  • /opt/local/lib for libraries
  • /opt/local/include for header files

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

sudo port install libusb

to install libusb1.0 or

sudo port install libusb-legacy

to install 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).

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.

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).

Claytor answered 13/10, 2010 at 16:26 Comment(3)
Even better, install with Homebrew: "brew install libusb".Lightish
@louielouie: Why is that better?Intrust
@JonCage because this answer is from 2010. A lot has changed in five years. Homebrew is the best package manager for OS X at this time.Billmyre
S
2

once libusb is installed using following command:

brew install libusb

or

brew install libusb-compat

link libusb to the build system using

brew link libusb

to be able to configure any project depending on libusb, use pkg-config:

pkg-config --cflags libusb-1.0

and

pkg-config --libs libusb-1.0

before calling any ./configure

Sidestep answered 7/12, 2022 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.