Riley Testut
Riley Testut

Reputation: 451

"dyld: Symbol not found:" for iOS 6-exclusive class in Static Library

NOTE: Yes, I know iOS 6 is under NDA. This question has nothing to do with iOS 6, expect for the fact that the class that I'm referencing is new in iOS 6.

I'm creating a static framework for use in several of my projects, which allows me to use a new API in iOS 6 if it's available, and if it's not it'll fall back to an iOS 5 equivalent. However, although I make sure to always check if a class is valid before using it like so:

if ([NewClass class]) {
    NewClass *newClass = [[NewClass alloc] init];
    // etc.
}

Whenever I launch my app in the iOS 5 Simulator, I get the following error:

dyld: Symbol not found: _OBJC_CLASS_$_NewClass

(where NewClass stands for the iOS 6 class).

This seems to be an issue just with using a static library, as if I include the certain files that reference the API directly in my project and reference them, it will launch with no issues. I've even tried weak-linking the static library, and it still crashes. The only option that works is weak-linking UIKit, but I would prefer to not have to do that due to UIKit being quite a large framework, and weak-linking takes extra time.

So basically, what can I do to weak link this class in the static library itself?

Upvotes: 3

Views: 1425

Answers (1)

Klaas
Klaas

Reputation: 22763

I guess your IPHONEOS_DEPLOYMENT_TARGET is not set to iOS 5? I just had the same error, because it was already on iOS 6. After setting it to iOS 5, everything was fine.

You can find the configuration both under Target->BuildSettings->IPHONEOS_DEPLOYMENT_TARGET and under Target->Summary->iOS Application Target.

Another approach to avoid this kind of error would be this:

Class myClass = NSClassFromString(@"NewClass")
if( myClass ) {
   NSObject *myResult = [myClass aMethod:@"Hello World"];
}

Upvotes: 3

Related Questions