I want to link a library conditionally (I have this library for iOS device, but I don't have it for Simulator). I am using Xcode 4.6 and iOS 6.1.
I read a question (and couple similar ones): iOS conditional link static library
-weak_library linker flag
I tried ry to build the project with following flags:
-weak_library LibraryNameWithPath
However it gives me an error:
ld: file not found: LibraryNameWithPath
-weak-l linker flag
I tried to build it with following flags:
-weak-lShortLibraryName
And got the same results :
ld: library not found for -lShortLibraryName
Thoughts
Why the heck, does it check for library existence, if it is explicitly marked to be a weak link?
Is there a way to do conditional linking in build time (vs runtime usage of dlopen, dlclose and friends)?
Follow these steps to create a sample iPhone application to use the iOS Binding Library created above: Create Xamarin.iOS Project - Add a new Xamarin.iOS project named InfColorPickerSample using the Single View App template:
When working on iOS, you might encounter cases where you want to consume a third-party Objective-C library. In those situations, you can use a Xamarin.iOS Binding Project to create a C# binding that will allow you to consume the library in your Xamarin.iOS applications. Generally in the iOS ecosystem you can find libraries in 3 flavors:
Generally in the iOS ecosystem you can find libraries in 3 flavors: As a precompiled static library file with .a extension together with its header (s) (.h files). For example, Google’s Analytics Library As a precompiled Framework.
You can use the iOS Builder API to build Dynamic Links from parameters, or to shorten a long Dynamic Link. To create a Dynamic Link, create a new DynamicLinkComponents object and specify the Dynamic Link parameters by setting the object's corresponding properties.
I actually haven't tried to do this with build flags directly, but I've done it with the Xcode GUI settings. Select your build Target, then Build Phases, and then choose to add your static library to the list of binaries to link.
However, select Optional (which is not the default) from the Required/Optional menu on the right.
Since this is a static library you're talking about, I think you'd then need to put some preprocessor guards in your code, to disable use of the library in the simulator:
#if TARGET_IPHONE_SIMULATOR
NSLog(@"do nothing here!");
#else
HelloLibrary* hl = [[HelloLibrary alloc] init];
NSString* result = [hl helloLibraryFoo];
#endif
I did nothing else to make this work (no other Build Settings were modified).
When building for the simulator, I just get this warning:
ld: warning: ignoring file /Users/me/Desktop/code/MyAppName/libHelloLibrary.a, file was built for archive which is not the architecture being linked (i386): /Users/me/Desktop/code/MyAppName/libHelloLibrary.a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With