views:

34

answers:

1

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?

+1  A: 

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.

Nicholas Riley