Export an `OBJC_CLASS` from one static lib as part of another

余生长醉 提交于 2019-12-06 01:30:42

I think I may have solved it with single-object prelink (basically this means it does an ld -r to build a giant object file, then passes that to libtool), although I'm still not sure, and I don't love the solution. So, I will post what I've got as an answer, but hope someone else comes along with a better answer.

To get single-object prelink to work, you need to (in LibB):

  • Add libLibA.a as a Framework.
  • Make sure it does not appear in the Link Binary With Libraries build phase.
  • Set "Dead Code Stripping" to No.
  • Set "Don't Dead-Strip Inits and Terms" to Yes.
  • Set `Perform Single-Object Prelink" to Yes.
  • Set "Prelink libraries" to ${PROJECT_DIR}/libLibA.a
  • Set "Preserve Private External Symbols" to Yes.

(The second step is what I was doing wrong earlier…)

Unfortunately, this seems to break the dependency rules completely, so that every build recompiles every .m (and .pch) that's part of the target, even if nothing has changed.

Other than that annoyance, this seems to work for both AppC and my real project just fine.

AppC does not need "Preserve Private External Symbols"; my real project does. I believe this is because one of the third-party libraries does an ld -r with an empty -exported_symbols_list explicitly to "transform all symbols to private_extern. Otherwise, class objects don't end up that way. However, I'm not 100% sure I understand this one.

Adding this to Other Linker Flags appears to work

-force_load $(CONFIGURATION_BUILD_DIR)/libLibA.a
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!