Fix build on macOS Apple Silicon (darwin-aarch64)#18
Open
axgd-code wants to merge 1 commit intousb4java:masterfrom
Open
Fix build on macOS Apple Silicon (darwin-aarch64)#18axgd-code wants to merge 1 commit intousb4java:masterfrom
axgd-code wants to merge 1 commit intousb4java:masterfrom
Conversation
When building libusb4java with a statically linked libusb on macOS, the
linker fails with undefined symbols for CoreFoundation, IOKit, Security and
objc because libusb itself depends on those Apple frameworks.
Add an APPLE-guarded block in src/CMakeLists.txt that links those four
system frameworks when building on macOS:
if(APPLE)
target_link_libraries(usb4java
"-framework CoreFoundation"
"-framework IOKit"
"-framework Security"
"-lobjc"
)
endif()
Without this change the build script (dists/darwin/build) fails at the link
step with errors like:
Undefined symbols for architecture arm64:
_IOCreatePlugInInterfaceForService, referenced from ...
_kIOMasterPortDefault, referenced from ...
Verified on macOS 15 (Sequoia) / Apple M3 with Temurin JDK 21.
Fixes usb4java#12 and closes usb4java/usb4java#86.
This was referenced May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Building
libusb4javaon macOS Apple Silicon (darwin-aarch64) fails at the link step with undefined symbols:This happens because the build script (
dists/darwin/build) links libusb statically. The staticlibusb-1.0.aon macOS depends on Apple system frameworks (CoreFoundation,IOKit,Security) and the Objective-C runtime (objc), which are not automatically pulled in by CMake.This issue was first reported in #12 and is also tracked upstream at usb4java/usb4java#86. It affects all Apple Silicon Macs (M1/M2/M3/M4) running macOS. Related discussion: marian-m12l/studio#244.
Fix
Add an
APPLE-guarded block insrc/CMakeLists.txtthat links the required macOS system frameworks:This is the standard CMake idiom for linking Apple frameworks. The block is gated on
APPLEso it has no effect on Linux or Windows builds.Verification
Verified on:
libusb4java.dylibloads correctly via JNI andLibUsb.init()returns 0The resulting
darwin-aarch64JAR has been tested with TomTomWatch connecting to a physical TomTom GPS watch over USB.