cocoa 插件中重复的冲突框架

发布于 2024-08-31 19:17:31 字数 132 浏览 15 评论 0原文

我目前正在为我的应用程序编写一个插件框架。我希望能够发布插件而无需更新我的应用程序,并且我打算使该框架可用于第三方插件。当两个插件附带相同的框架时,我目前遇到了问题。当插件加载时,运行时会变得混乱,因为框架被加载了两次。缓解这个问题的最佳方法是什么?

I am currently writing a plug-in framework for my application. I would like to be able to release plugins without having to update my application, and I intend on making the framework available for third party plugins. I am currently running into issues when two plugins ship with identical frameworks. When the plugins are loaded the runtime gets confused because the framework gets loaded twice. What is the best way to mitigate this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿与i 2024-09-07 19:17:31

有点不清楚你在问什么。您的意思是这些插件都包含您的框架或其他第三方框架?

如果它们都包含您的框架,那么您不应该这样做;他们应该引用嵌入在您的应用程序中的框架。您可以通过@executable_path引用框架包,因此它与您的应用程序相关(例如@executable_path/../Frameworks/MyFramework.framework/)。

这是来自 Lightroom 的示例:

% otool -L Applications/Adobe\ Lightroom\ 2.app/Contents/PlugIns/Web.lrmodule/Contents/MacOS/Web
Applications/Adobe Lightroom 2.app/Contents/PlugIns/Web.lrmodule/Contents/MacOS/Web:
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 12.0.0)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 136.0.0)
    @executable_path/../Frameworks/AgSubstrate.framework/Versions/A/AgSubstrate (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)

如果它们都包含其他第三方 Objective-C 框架,则这是插件中的错误; Objective-C 运行时没有命名空间,当您加载多个同名的类时,您不能期望得到任何正常的响应。 这个问题对此进行了讨论,它提供了几种针对 ObjC 命名空间冲突的解决方法。

It's a bit unclear what you're asking. Do you mean that the plugins both include your framework, or other third-party frameworks?

If they both include your framework, then you shouldn't do it that way; they should reference a framework embedded in your application. You can reference the framework bundle via @executable_path so it's relative to your application (e.g. @executable_path/../Frameworks/MyFramework.framework/).

Here's an example from Lightroom:

% otool -L Applications/Adobe\ Lightroom\ 2.app/Contents/PlugIns/Web.lrmodule/Contents/MacOS/Web
Applications/Adobe Lightroom 2.app/Contents/PlugIns/Web.lrmodule/Contents/MacOS/Web:
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 12.0.0)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 136.0.0)
    @executable_path/../Frameworks/AgSubstrate.framework/Versions/A/AgSubstrate (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)

If they both include other third-party Objective-C frameworks, this is a bug in the plugins; the Objective-C runtime doesn't have namespaces and you can't expect any sane response when you load multiple classes with the same name. This is discussed in this question, which provides several workarounds for ObjC namespace collisions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文