The following is from StackOverflow:
At build time the static linker on OS X, ld, writes the shared library identifier of each library that your application links against in to the application binary. At run time the dynamic linker, dyld, attempts to load each shared library from the paths specified in the application binary. You can see this information using
otool -L YourApp.app/Contents/MacOS/YourApp
.
The fact you needed to symlink libmysqlclient.18.dylib in to /usr/lib suggests that the shared library identifier of libmysqlclient.18.dylib is something like /usr/lib/libmysqlclient.18.dylib. To include the library in your .app bundle in a way that your application will use it rather than looking in /usr/lib you need to:
- Change the shared library identifier of libmysqlclient.18.dylib so that dyld will look for the binary relative to your application binary. This is typically done by running
install_name_tool -id @executable_path/../Frameworks/libmysqlclient.18.dylib libmysqlclient.18.dylib
. - Copy the modified libmysqlclient.18.dylib in to the Frameworks subdirectroy in your application bundle. This is typically done using a Copy Files build phase in your Xcode project.
You should then be able to verify that the install name written in to your application binary is
@executable_path/../Frameworks/libmysqlclient.18.dylib
rather than
/usr/lib/libmysqlclient.18.dylib
(using
otool -L YourApp.app/Contents/MacOS/YourApp
again). If the install name isn't correct then you'll need to ensure that your linker search path is set up to find your modified version of libmysqlclient.18.dylib ahead of any other versions you may have.