Optional platform not working (CoreAudioKit not in simulator)

To work with MIDI via Bluetooth, I need to use the CoreAudioKit framework. This works fine, but I cannot compile on a simulator.

  • Creating a "optional" frame does not help, ld: framework not found CoreAudioKit error ld: framework not found CoreAudioKit

enter image description here

I think it should work according to the docs

  1. Removing the framework allows me to compile my code

I have this in my code, so I can remove the framework without any problems.

 #if !TARGET_IPHONE_SIMULATOR #import <CoreAudioKit/CoreAudioKit.h> #endif 


How can I make this extra compilation work?
+7
ios ios-simulator coremidi
source share
2 answers

I would have thought it would work, but I think you can solve it differently. This worked for me:

  • remove all links to CoreAudioKit in your target settings of the Link Binary With Libraries

  • make sure that no identical settings are entered manually. for example, do not add this option: -weak_framework CoreAudioKit to Other linker flags

  • use preprocessor flags to conditionally compile code for a simulator:

 #import "ViewController.h" #if !TARGET_IPHONE_SIMULATOR @import CoreAudioKit; #endif @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. #if !TARGET_IPHONE_SIMULATOR if ([CABTMIDICentralViewController class]) { // maybe not needed? CABTMIDICentralViewController *vc = [[CABTMIDICentralViewController alloc] init]; } #endif } 

Note. In my example above, you may not need to check for the existence of the CABTMIDICentralViewController class. It depends on whether your application is aimed only at iOS 8+, as well as iOS 7.

Update

In the comments below @Yar and @JeremyHuddlestonSequoia, note that this solution requires Enable modules and Link Frameworks in the project build settings. These Xcode settings now default to the correct values ​​for this technology, but if you are managing an older project, make sure they are turned on.

Other links

fooobar.com/questions/188642 / ...

fooobar.com/questions/125103 / ...

+6
source share

To link something (even weak), it must be present in the SDK. It doesn't matter if you really use the framework; the linker will fail if instructed to include a link to a file that it cannot find.

You will need to conditionally compile and link your project based on the SDK used. In particular, when setting up the iOS SDK, you want to enable support and a link to CoreAudioKit.framework. When targeting the iOS Simulator SDK, you don’t want to include this support and binding.

To conditionally define the 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 heading is often pulled through others, but it's best to do it yourself.

For example:

 #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 binding in the build phases for targets, so make sure you do not include CoreAudioKit.framework in the build phase of Link Binary With Libraries for your purpose. For link processing, you basically have two options:

  • Use automatic link support from clang modules.
  • Use SDK Legend Linker Flags

To use auto-binding, you must install Xcode Include Modules (C and Objective-C) and Link Structures .

If you are trying to do something similar with old toolchains or just with tighter control over binding, you can still accomplish this using the SDK conditional Other flag builders . Create conditional SDK entries for this build option to use “-framework CoreAudioKit” (or “-weak_framework CoreAudioKit”) by default and do nothing when setting up the simulator SDK. This screenshot should make it clearer.

build settings screenshot

If your goal of deploying iOS is older than iOS 8, you should be sure that the framework link is weak because it was added in iOS 8. If you plan to use iOS 8 or later, you can safely use -framework CoreAudioKit.

+2
source share

All Articles