I have an application and a dylib that it links against. It is my understanding that the application bundle should contain the dylib. Is that correct?
Is there a way to copy the dylib to the application bundle when built?
Thanks, Alan
Is there a way to copy the dylib to the application bundle when built?
Well, sure -- with a little shell scripting, anything is possible. :)
In your build script, after you've called macdeployqt, but before you've done any code-signing, you'd copy the .dylib file over into the Contents/Frameworks inside your .app folder.
The trick after that is convincing the executable to look for the library in its new location rather than the location it was in when you linked the executable. (If you do a "otool -L ./MyProgram.app/Contents/MacOS/MyProgram" you will see the places where the program is looking for shared libraries, and you will see that it is not looking for your .dylib file in the Frameworks folder, yet)
To do that you use the install_name_tool command, e.g.:
install_name_tool -change /the/old/path/to/the_library_name.dylib "@executable_path/../Frameworks/the_library_name.dylib" ./MyProgram.app/Contents/MacOS/MyProgram
After doing that you can run "otool -L" on your executable again to verify to your satisfaction that the executable is now set to look for the .dylib file inside the Frameworks folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With