Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including a static library inside a dynamic framework in iOS

I needed to create a framework (which requires a static library) for a project I'm working on. I used this tutorial to create the framework, then copied the static library into the project and it worked.

But, when I dragged the framework to an iOS project, it shows a ton of errors.

`Undefined symbols for architecture i386:"_OBJC_CLASS_$_SomeClassFromTheStaticLibrary",referenced from:_OBJC_CLASS_$_AnotherClass in MyFramework`

What I think is happening is that the iOS project wants to recompile the framework and it cannot, because it can't locate the static library. All errors disappear if I add the static library to the iOS project. This is what I want to avoid.

Basically I want to have the iOS project -> Framework -> Library instead of having the library in both the project and the framework.

I have tried adding the static library as a resource in the framework, but it didn't work.

like image 598
olivaresF Avatar asked Mar 17 '12 03:03

olivaresF


People also ask

What is static and dynamic library in iOS?

Using dynamic libraries instead of static libraries reduces the executable file size of an app. They also allow apps to delay loading libraries with special functionality only when they're needed instead of at launch time. This feature contributes further to reduced launch times and efficient memory use.

What is static library and dynamic library in iOS Swift?

Static framework contain a static library packaged with its resources. Dynamic framework aka Embedded framework - from iOS v8 - contains the dynamic library and resources. In addition to that, dynamic framework can include different versions of the same dynamic library in a single bundle ( versioned bundle ).

Are dynamic libraries allowed iOS?

dylib, are not supported on iOS, watchOS, or tvOS, except for the system Swift libraries provided by Xcode. You're not allowed to create these, as this will get your app rejected. Only Apple is allowed to create dynamic libraries for iOS.

How can I tell if my library is static or dynamic iOS?

If you are looking at a binary library / framework (perhaps it's precompiled by a 3rd party) and want to know if it's a static or dynamic binary, just use file command with the path to the binary file. Example (static framework) - static binaries are usually marked with ar archive or similar.


1 Answers

I doubt this is possible. When you think about what is happening you will see the problem.

  1. The framework is compiled and the static library is processed so that things like extra symbols are stripped out
  2. The app is now compiled and linked against the framework which may or may not have had the symbols that the app is requiring

I did get this to work if ONLY the framework was using the static library (logical) but I can't find a way to share the code across the framework & the app.

like image 115
Paul de Lange Avatar answered Nov 11 '22 15:11

Paul de Lange