Library Conditional Link on iOS

I want to conditionally link the library (I have this library for the iOS device, but I do not have it for Simulator). I am using Xcode 4.6 and iOS 6.1.

I read a question (and a couple of similar ones): iOS static conditional link library

-weak_library linker flag

I tried ry to build a project with the following flags:

-weak_library LibraryNameWithPath 

However, this gives me an error:

 ld: file not found: LibraryNameWithPath 

-weak-l linker flag

I tried to build it using the following flags:

 -weak-lShortLibraryName 

And got the same results:

 ld: library not found for -lShortLibraryName 

thoughts

Why the hell is he checking the existence of a library if it is clearly marked as a weak link?

Is there a way to do conditional binding at build time (against using dlopen, dlclose and friends at run time)?

+5
source share
1 answer

In fact, I did not try to do this directly using the build flags, but I did it with the Xcode GUI settings. Select your Target design, then Phase Build , and then select to add your static library to the list of binaries for reference.

However, select Optional (which is not standard) from the Required / Optional menu on the right.

enter image description here

Since this is the static library you are talking about, I think you would need to put some preprocessor guards in your code to disable the 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 changed).

When creating for the simulator, I just get this warning:

ld: warning: ignoring file /Users/me/Desktop/code/MyAppName/libHelloLibrary.a, the file was created for an archive that is not related to architecture (i386): /Users/me/Desktop/code/MyAppName/libHelloLibrary.a

+4
source

All Articles