How do I handle duplicated symbols in a loadable NSBundle/plug-in?

Consider the following Cocoa project structure:

Host
|-- LoadablePlugIn
|   |-- Main.storyboard
|   |-- Info.plist
|   |-- TDWLPIClassOne.h
|   |-- TDWLPIClassOne.m
|   |-- TDWLPIClassTwo.h
|   |-- TDWLPIClassTwo.m
|-- TDWAppDelegate.h
|-- TDWAppDelegate.h
|-- TDWClassOne.h
|-- TDWClassOne.m
|-- TDWUtils.h
|-- TDWUtils.mm
|-- Base.lproj
|   `-- Main.storyboard
|-- Info.plist
`-- main.m

Here the root folder refers to sources of the Host target (the main executable target), while LoadablePlugIn refers to resources of an embedded plug-in target with corresponding name. Both targets at the same time want to use TDWUtils symbols for their own purposes, so I add TDWUtils.mm to compile sources of both Host and LoadablePlugIn targets. It compiles and works without issues, however since the LoadablePlugIn is supposed to load during run-time the linker is not able to locate duplicated symbols of TDWUtils.mm in the binaries and I’m not sure if that is a robust scenario:

...
Class plugInPrincipalClass = [NSBundle bundleWithURL:loadablePlugInURL].principalClass;
NSWindowController *windowController = [plugInPC instantiateInitialController];
...

Should I compile LoadablePlugIn with hidden symbols compiler flag (like -fvisibility=hidden) or use any other technique to prevent the name collision or can I just leave it as is because in both binaries the symbols of TDWUtils have exactly the same implementation?

Both targets at the same time want to use TDWUtils symbols for their own purposes

The best way to handle this depends on the nature of that code. There are two factors:

  • Is the code large? — If it is, you want to take steps to share it rather than ship two copies.

  • What language is the code written in? — Most notably, Objective-C uses a single namespace for its classes, so you can’t load two copies of a class in the process even if you do manage to avoid linker issues.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How do I handle duplicated symbols in a loadable NSBundle/plug-in?
 
 
Q