I'm trying to use libusb in a macOS application with GUI. But I always fail with "No such module 'CLibUSB'". I could use CLibUSB in a command line application, but cannot get it to work with a macOS GUI application. What I did:
- brew install libusb
- $ mkdir Clibusb and $ cd Clibusb/
- make a system module
$ swift package init --type system-module
- Edit the package manifest Package.swift file to look like this
// swift-tools-version:5.1
import PackageDescription let package = Package( name: "Clibusb", pkgConfig: "libusb-1.0", providers: [ .brew(["libusb"]) ], dependencies: [ // Dependencies declare other packages that this package depends on // .package(url: /* package url */, from: "1.0.0"), ] )
- Create a C shim header,
echo '#include <libusb.h>' >shim.h
- Write the module map module.modulemap
module CLibUSB [system] { header "shim.h" link "libusb-1.0" export * }
- Create a Git repository
git init
git add .
git commit -m "Initial commit"
- Make a client app
mkdir LibUSBExample cd LibUSBExample swift package init --type executable
- In the client app in main.swift. I import CLibUSB and do some tests - all that works
How can I use CLibUsb in a GUI Application?