简体   繁体   English

如何在Qt中的Mac应用程序包中捆绑dylib?

[英]How can I bundle a dylib within a Mac app bundle in Qt?

I have an application and a dylib that it links against. 我有一个应用程序和它链接的dylib。 It is my understanding that the application bundle should contain the dylib. 我的理解是应用程序包应该包含dylib。 Is that correct? 那是对的吗?

Is there a way to copy the dylib to the application bundle when built? 有没有办法在构建时将dylib复制到应用程序包?

Thanks, Alan 谢谢,艾伦

Is there a way to copy the dylib to the application bundle when built? 有没有办法在构建时将dylib复制到应用程序包?

Well, sure -- with a little shell scripting, anything is possible. 嗯,当然 - 只需要一点shell脚本,一切皆有可能。 :) :)

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. 在您的构建脚本中,在您调用macdeployqt之后,但在完成任何代码签名之前,您将.dylib文件复制到.app文件夹中的Contents / Frameworks中。

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) (如果您执行“otool -L ./MyProgram.app/Contents/MacOS/MyProgram”,您将看到程序正在查找共享库的位置,您将看到它没有查找您的.dylib文件还有Frameworks文件夹)

To do that you use the install_name_tool command, eg: 为此,您可以使用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

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. 执行此操作后,您可以再次在可执行文件上运行“otool -L”以验证您的可执行文件现在已设置为在Frameworks文件夹中查找.dylib文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM