Skip to content

Instantly share code, notes, and snippets.

@naus3a
Created February 11, 2021 11:49
Show Gist options
  • Save naus3a/1eef79964d36c6ba0ccc080e42d5299a to your computer and use it in GitHub Desktop.
Save naus3a/1eef79964d36c6ba0ccc080e42d5299a to your computer and use it in GitHub Desktop.
dylib checking and embedding

How to check where you library wants to live: $ otool /pathToLib/lib.dylib

How to tell your app to get the lib from another path: $ install_name_tool -change /pathLibWantsToBe/lib.dylib /pathYouNeed/lib.dylib /pathToApp/AppName.app/Contents/MacOS/AppName

Let's say you want the lib to be embedded in your app (supposing you're using XCode):

  • add the library to your project (drag it in Frameworks / BuildPhases -> Link Binary With Libraries)
  • Go to BuildPhases -> CopyFiles, set Destination to Frameworks and add the library to the list. This will copy it to the Frameworks folder in your bundle.
  • In BuildPhases -> RunScript add: install_name_tool -change /pathLibWantsToBe/lib.dylib @executable_path/../Frameworks/lib.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$ProductName";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment