In order to link something (even weakly), it needs to be present in the SDK. It doesn't matter if you don't actually use the framework; the linker will error out if instructed to include a link to a file it cannot find.
You will need to conditionally compile and link your project based on the SDK being used. Specifically, when targeting the iOS SDK, you will want to include support for and link against CoreAudioKit.framework. When targeting iOS Simulator SDK, you will want to not include this support nor linkage.
To conditionalize your code, you will want to include the header and use the TARGET_OS_SIMULATOR macro (or the deprecated TARGET_IPHONE_SIMULATOR macro for SDKs older than iOS 9.0). This header is often pulled in via other includes, but it is best to do so yourself.
Eg:
#import "MyController.h"
#import <TargetConditionals.h>
#if !TARGET_IPHONE_SIMULATOR
#import <CoreAudioKit/CoreAudioKit.h>
#endif
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
#if !TARGET_IPHONE_SIMULATOR
// Stuff dependent on CoreAudioKit
#endif
}
@end
Xcode does not support SDK-conditional linking in the build phases for targets, so make sure you do not include CoreAudioKit.framework in Link Binary With Libraries build phase for your target. To handle linking, you basically have two options:
- Use automatic linking support from clang modules
- Use SDK-conditional linker flags
To use automatic linking, you must set Xcode's Enable Modules (C and Objective C) and Link Frameworks Automatically build settings turned on.
If you are trying to accomplish something like this with older toolchains or just like having tighter control over linking, you can still accomplish this with SDK-conditional Other Linker Flags build settings. Create SDK-conditional entries for this build setting such that you use "-framework CoreAudioKit" (or "-weak_framework CoreAudioKit") by default and nothing when targeting the simulator SDK. This screenshot should make it more clear.
If your iOS Deployment Target is older than iOS 8, you should be sure to weak link the framework because it was added in iOS 8. If targeting iOS 8 or newer, you can safely use -framework CoreAudioKit.
CABTMIDICentralViewController
... The thing that surprised me about this was the use of@import
, and the need to turn it on per this answer: https://mcmap.net/q/378096/-can-39-t-import-embedded-framework-with-xcode-6-gm BIG THANKS for helping resolve this issue. Great! – Newport