我有一个应用程序和一个它链接的 dylib。据我了解,应用程序包应包含 dylib。对吗?
有没有办法在构建时将 dylib 复制到应用程序包中?
谢谢, 艾伦
最佳答案
Is there a way to copy the dylib to the application bundle when built?
好吧,当然 - 使用一点 shell 脚本,一切皆有可能。 :)
在您的构建脚本中,在您调用 macdeployqt 之后,但在您完成任何代码签名之前,您需要将 .dylib 文件复制到您的 .app 文件夹内的 Contents/Frameworks 中。
之后的技巧是说服可执行文件在其新位置而不是链接可执行文件时它所在的位置查找库。 (如果你执行“otool -L ./MyProgram.app/Contents/MacOS/MyProgram”你会看到程序正在寻找共享库的地方,你会看到它不是在寻找你的.dylib文件Frameworks 文件夹)
为此,您可以使用 install_name_tool 命令,例如:
install_name_tool -change /the/old/path/to/the_library_name.dylib "@executable_path/../Frameworks/the_library_name.dylib" ./MyProgram.app/Contents/MacOS/MyProgram
完成此操作后,您可以再次对可执行文件运行“otool -L”,以确认可执行文件现在已设置为在 Frameworks 文件夹中查找 .dylib 文件并令您满意。
关于c++ - 如何在 Qt 的 Mac 应用程序包中 bundle dylib?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33333628/