Repository navigation
Link IOKit and CoreFoundation into the shared library on macOS - #368
Conversation
With -DBUILD_SHARED_LIB=ON the Darwin USB backend's IOKit and CoreFoundation frameworks were only appended to MTP_LIBRARIES, which the shared library target does not use, so linking libmtp-ng.dylib failed with undefined symbols (_CFUUIDGetConstantUUIDWithBytes, _IOCreatePlugInInterfaceForService, ...). Append them to MTP_SHARED_LIBRARIES as well, mirroring what the static library already gets.
CMake strips the build tree rpath when installing, and nothing set CMAKE_INSTALL_RPATH, so an installed aft-mtp-cli built with -DBUILD_SHARED_LIB=ON could not load @rpath/libmtp-ng.dylib. Default it to @loader_path/../lib on macOS unless the packager already set one.
|
Some context on why this matters beyond the build itself: I am adding If the change looks right to you, a release that includes it (master has carried the 4.6 version bump since May 2025) would let Homebrew pick it up. Happy to adjust anything in this PR. |
|
Thanks for merging! One follow-up ask: would you tag a The concrete blocker on my side is the Homebrew formula (Homebrew/homebrew-core#316024): the maintainers there require new formulae to build the shared library and do not take patches, so their verdict was "it will need to wait for a release with a fix either way". A stable tag with this change is the only thing standing between that PR and being merged. No rush beyond that, and thanks again for the quick merge. |
Building with
-DBUILD_SHARED_LIB=ONon macOS fails at link time:The Darwin backend appends IOKit and CoreFoundation to
MTP_LIBRARIESonly, which the shared library target does not link (MTP_SHARED_LIBRARIESis used there), solibmtp-ng.dylibis left with unresolved framework symbols. The static library path gets the frameworks throughMTP_LIBRARIES, which is why the default build works.This appends the two frameworks to
MTP_SHARED_LIBRARIESas well, mirroring the libusb branch that already links its library into the shared target.Verified on macOS 27 (arm64) with
-DBUILD_SHARED_LIB=ON -DBUILD_QT_UI=OFF -DBUILD_FUSE=OFF -DBUILD_MTPZ=OFF -DBUILD_PYTHON=OFF -DBUILD_TAGLIB=OFF:libmtp-ng.dyliblinks,aft-mtp-clilinks against it and runs.Second commit: after installing,
aft-mtp-clifrom the shared build still could not start (dyld: Library not loaded: @rpath/libmtp-ng.dylib) because CMake drops the build tree rpath on install and nothing setsCMAKE_INSTALL_RPATH. It now defaults to@loader_path/../lib${LIB_SUFFIX}on macOS for the shared build when the packager has not set one, so a plaincmake --installgives a working binary. The default static build is unchanged.