Question

My company makes a static library for iOS apps. One annoying step for developers is that they have to manually link against all the required frameworks that the library uses, and failing to do so leads to somewhat confusing compiler errors.

I would have previously thought this wasn't possible, but the company Chartboost claims to automatically link against non-default frameworks like AdSupport and StoreKit. Based on my testing in their sample app (available from the linked page), so far this appears to be the case (Even when disabling "Enable Modules" and "Link Frameworks Automatically" in the app that links against the static library).

Is there some way to enable this feature when creating a static library? I've tried enabling modules and the "Link Frameworks Automatically" LLVM options in Xcode, but so far haven't been able to get it working.

Was it helpful?

Solution

There's a piece of code called CBDynamicallyLoadedDependencies that calls dlopen() on the appropriate system library before making the function or method call.

My original answer wasn't correct. the dlopen() call is just in the x86 code. On the device, it's something different, but my ARM assembly isn't strong enough to figure it out. All I can say is that there's a piece of code that's acting as a trampoline to the desired functions and that references the system library files (like /System/Library/Frameworks/AdSupport.framework/AdSupport).

But the point is that it's not a simple project trick that makes it work normally. There's internal code involved.

OTHER TIPS

They might use modules you mentioned and @import instead of #import, which should make the libraries link automatically.

For reference, check this question.

This might not be what you're looking for, but if you don't yet support Cocoapods, I would strongly advise taking a look:

http://cocoapods.org/

(Edit: Cocoapods is essentially linked to Xcode. Other IDEs will need another solution.)

You can advertise Cocoapods to developers as the "easy" way to work with your library, and the manual method as...well, the manual method. ;)

I'm not aware of any industry resistance to Cocoapods, so I don't see a downside to supporting it, and it does solve the problem you're talking about (albeit in a roundabout sort of way).

Also I've found Chartboost VERY developer-friendly. You might even reach out to them and ask.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top