简体   繁体   English

在iOS中的动态框架中包含静态库

[英]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. 但是 ,当我将框架拖到iOS项目时,它显示了大量的错误。

`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. 我认为正在发生的是iOS项目想要重新编译框架而不能,因为它找不到静态库。 All errors disappear if I add the static library to the iOS project. 如果我将静态库添加到iOS项目,所有错误都会消失。 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. 基本上我想要iOS项目 - > Framework - > Library,而不是在项目和框架中都有库。

I have tried adding the static library as a resource in the framework, but it didn't work. 我已经尝试将静态库添加为框架中的资源,但它不起作用。

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. 如果只有框架使用静态库(逻辑),我确实让它工作,但我找不到在框架和应用程序之间共享代码的方法。

If a symbol is hidden (either via Symbols Hidden by Default/ GCC_SYMBOLS_PRIVATE_EXTERN being set to YES or __attribute__ ((visibility ("hidden"))) being applied to certain symbols), then that symbol will be available when statically linking the library, but not when dynamically linking the framework. 如果隐藏符号(通过默认隐藏的符号/ GCC_SYMBOLS_PRIVATE_EXTERN设置为YES__attribute__ ((visibility ("hidden")))应用于某些符号),则静态链接库时该符号将可用,但不是在动态链接框架时。

Ensure that the static library's symbols are not hidden, and you should be able to access them from your app. 确保不隐藏静态库的符号,并且您应该能够从应用程序访问它们。

I have followed this link to create custom framework. 我已经按照此链接创建自定义框架。 I have static library inside my framework and it works fine with that. 我的框架中有静态库,它可以正常工作。

I have copied his steps in my blog for my understanding along with a script to make it universal. 我已经在我的博客中复制了他的步骤,以便我的理解和脚本使其具有普遍性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM