Making Xcode embed necessary dylibs

I never used "Embedded Libraries", but instead a copy phase to copy all needed 3rd party libs and those created by the various targets in the project. You can simply drag dylibs you wanna copy from the "Frameworks" and "Products" outline nodes into this copy phase (or add them via the "+" button). XCode will also automatically sign each lib, if that's enabled (which it is by default):

enter image description here

Take also a look at the "Installation Directory" setting. You should set this value to @executable_path/../Frameworks (provided this is your actual framework folder, at least that is the recommended one). The value is used by XCode to set the ID for your dylib and is essential to make them load correctly

enter image description here

You can also use a tool like MacDependency to check the details of your .app, .dylib and .framework packages. It will show you also which other dylibs a library depends on and under which path it expect them. That path must be the same as the ID of the linked library or loading will fail.

Another very useful tool is otool, which comes with XCode. It gives similar infos like MacDependency and more. Here is a list of dependencies for a dylib with paths and versions expected by it:

Mikes-iMac:Debug mike$ otool -L libcdbc.dylib
libcdbc.dylib:
    @executable_path/../Frameworks/libcdbc.dylib (compatibility version 1.0.0, current version 1.0.0)
    @executable_path/../Frameworks/libwbbase.dylib (compatibility version 1.0.0, current version 1.0.0)
    @executable_path/../Frameworks/libgrt.dylib (compatibility version 1.0.0, current version 1.0.0)
    @executable_path/../Frameworks/libgmodule-2.0.0.dylib (compatibility version 3401.0.0, current version 3401.2.0)
    @executable_path/../Frameworks/libgthread-2.0.0.dylib (compatibility version 3401.0.0, current version 3401.2.0)
    @executable_path/../Frameworks/libglib-2.0.0.dylib (compatibility version 3401.0.0, current version 3401.2.0)
    @executable_path/../Frameworks/libmysqlcppconn.7.1.1.8.dylib (compatibility version 7.0.0, current version 7.1.1)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)

Another discussion about loader paths is here: How to set dyld_library_path in Xcode.

If your app or a library you created expects dylibs from a system location instead of a relative one then it could mean you linked the wrong lib to it. In the "Link Binary" build phase you can select the libraries to link against and the selection dialog lists all your project targets there. Also for the linker list you can simply drag a dylib from the "Products" node in your project outline into it to make the setting. Also for such libs the requirement to set a proper path holds true. You can do that with a script that changes the ID after the copy phase or you keep a copy of these libs somewhere else, change the IDs of them once (e.g. after you downloaded them) and copy them from there to your final app.


All of the above solutions are not working for later version of Xcode and iOS. This is updated with Xcode 13 and tested with iOS 14.

Here is a step by step guide:

  1. When the dylib is created, and make sure the "Install Directory" path for dylib's Build Setting is set as:

    @executable_path/Frameworks

  2. Copy your dylib to a subdirectory such as: ./libs/ under your project directory.

  3. In your project's Xcode Build Settings tab, Search Path ->Library Search Path has a path to the subdirectory in above 2).

  4. Select Build Phase, add your dylib to Copy Bundle Resource as well as Embedded Frameworks as shown bellow (see entries for libgrt.dylib as an example) :
    [Xcode Project Build Phase1

Make sure the path is Frameworks and leave subpath field empty.

Now build and test your app!


Embedding dylibs now works (checked with Xcode Version 10.2). Targets -> Frameworks, Libraries and Embedded content.

see https://help.apple.com/xcode/mac/11.0/index.html?localePath=en.lproj#/dev51a648b07