-
Notifications
You must be signed in to change notification settings - Fork 0
Homebrew
Homebrew is a great way to get C libraries that aren't wrapped in frameworks or packaged for Carthage. They often have licenses which are generally compatible with any type of application you might write.
It's not hard to put a Homebrew library in an Xcode application, but it's not obvious, either. Suppose you want to include libarchive with your application.
brew install libarchive
- copy /usr/local/opt/libarchive/{lib,include}/* to a Libraries/ folder
- copy /usr/local/opt/xz/lib/liblzma.5.dylib to a Libraries/ folder, too (you can discover this dependency by running "otool -L" on it, and looking for other /usr/local/opt lines)
- add the .dylibs to the Xcode project (I make a group for these: Frameworks -> C libraries)
- add the dylibs to the first "Copy Files" phase (the one BEFORE the linking phase!) (and make sure they have "Code Sign On Copy" checked, or you'll get a frustratingly mysterious error)
- be sure to add the libarchive license to your about panel, or somewhere appropriate
When adding raw .dylibs, there's extra work to do. If you get a dylib from Homebrew, its "ID" will be set to /usr/local/opt/whatever. You can't link to this as-is, because the user's computer won't have that path. You'll need to fix the paths before linking (or committing libraries to Libraries/ in the repo).
For example, here's how I fixed libarchive. The dylibs are copied to My.app/Contents/Frameworks/ in the bundle, and @executable_path is My.app/Contents/MacOS/, so I made them relative to that:
install_name_tool -id @executable_path/../Frameworks/libarchive.13.dylib Libraries/libarchive.13.dylib
install_name_tool -id @executable_path/../Frameworks/liblzma.5.dylib Libraries/liblzma.5.dylib
install_name_tool -change /usr/local/opt/xz/lib/liblzma.5.dylib @executable_path/../Frameworks/liblzma.5.dylib Libraries/libarchive.13.dylib