Symbol not found in flat namespace with [NSBundle load]

I am having an issue with Xcode 15 when I create an archive build of my application. The general structure I something like:

Main Application:

  • Links to staticLib.a

Plugins:

  • use datatypes in staticLib.a

When I build an archive build and load the bundle for the plugin, I get the following type of errors:

Error Domain=NSCocoaErrorDomain Code=3588 "dlopen(pluginBinary, 0x0109): symbol not found in flat namespace '_OBJC_CLASS_$_FIRST_MISSING_CLASS'"

This program runs fine and finds the plugins without issues if I run the program from Xcode. It also will run and find the plugins correctly if I build a release build using xcodebuild. Only if I use Archive does it fail to load these files in the flat namespace. The plugins and the main binary say they use the TWOLEVEL namespace using otool -hV on them.

If I link the static library to the plugin, I get undefined behavior because both are linking to the same binary. The plugins are using: -undefined dynamic_lookup in their linker flags.

Any ideas how to resolve this?

Thanks, Steven

I think I figured it out, because of course after I make a post I do. I turned off dead code stripping along with modifying the strip behavior to not remove global symbols on strip. The plugins now seem to load successfully.

Your original post mentions _OBJC_CLASS_$_FIRST_MISSING_CLASS. I presume that FIRST_MISSING_CLASS is the name of an Objective-C class that you control. Is that class defined in staticLib.a?

Share and Enjoy

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

Correct, just obfuscating the details a bit. The class that the plugin used wasn't used outside of the plugin so after the static linking and dead code stripping it was no longer in the symbol table. It took a lot of digging to find this, at least for me.

Just FYI, static libraries and Objective-C are not the best of friends. With static libraries it’s very easy to get into a situation where you have two instances of the same Objective-C class in your process. That triggers the dreaded duplicate class error. For example:

objc[22092]: Class BBBTest is implemented in both …/BBB1 … and …/BBB2 …. One of the two will be used. Which one is undefined.

This error isn’t fatal, but it should be. Even if both classes are identical, have two copies can result in weird runtime misbehaviour.

If you find yourself in this situation, put your common classes into a dynamic library and have all the clients access them from there.

Share and Enjoy

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

Symbol not found in flat namespace with [NSBundle load]
 
 
Q