iOS framework with dependencies

2019-01-29 03:43发布

I have created two iOS .frameworks

they both compile perfectly

my structure is as follows:

iPadProject
  - framework1
     - framework2

So Framework2 is included in framework1 and framework1 is included in the actual iPad Project

So my problem is, if I add both framework1 and framework2 into my iPadProject it won't compile because its whining about duplicate symbols from framework2 ( that's logical because it was already included in framework1)

But if i only include framework1 into my iPadProject when i access a method from framework1 that in his turn access a method from framework2 it crashes the application with "signal SIGABRT"

2条回答
一纸荒年 Trace。
2楼-- · 2019-01-29 04:06

the problem is that because it is nested right now, the linker links f2 into f1 -- BUT only the parts of f2 that are needed by f1.

like

f2 has 5 symbols (f2_1 - 5)
f1 uses f2_1 and f2_2 but NOT 3,4,5
=> the linker throws it away

now the app needs f2_3, f2_4 and f2_5 but they aren't there... but nobody knows that at compile time.


now you try to resolve it by linking the app with f2 again but as before nobody at compile time the linker optimized out f2_3 - 5 and they are assumed to be in f1 and so are duplicates!


the way to solve this Rob Napier already mentioned. Don't nest Frameworks (mainly not static ones / 3rd part ones)

a workaround is to pass -all_load to the linker when f1 links in f2!

查看更多
做个烂人
3楼-- · 2019-01-29 04:17

Do not nest static libraries, including iOS frameworks. As you've seen, it leads to major problems (it leads to even more problems when two frameworks each have their own version of the third). The final link step should link all libraries required; static libraries should never link other static libraries. There is no really good way to automate this; it just has to be part of the documentation for the framework.

You shouldn't be getting runtime exceptions, though, for failing to link a framework. You should be getting link-time failures that indicate that the symbol isn't defined. If you're getting a crash, that suggests you're doing something strange in your linking.

查看更多
登录 后发表回答