简体   繁体   English

iOS App包含静态库中的所有符号

[英]iOS App is including ALL symbols from static library

I have a problem that I haven't been able to resolve in regards to when I link my iOS App against one or more static libraries. 关于将我的iOS应用程序链接到一个或多个静态库时,我有一个无法解决的问题。 Here is the issue: 这是问题所在:

I am creating several static libraries (MACH-O type: Relocatable Object File) each of which contain a large number of symbols. 我正在创建几个静态库(MACH-O类型:可重定位目标文件),每个库都包含大量符号。 Each of these static libraries are FAT libraries, containing a slice for each iOS/Simulator architecture. 这些静态库中的每一个都是FAT库,其中包含每个iOS / Simulator体系结构的切片。 From my understanding, when I compile my iOS Application only the symbols that are used by my App should be compiled into and included in my App, however, ALL of the symbols are being included. 据我了解,当我编译iOS应用程序时,仅应将应用程序使用的符号编译并包含在我的应用程序中,但是,所有这些符号都将包含在内。

I've done some testing using otool , nm , and other tools and can see that when I link against any of these libraries, even if I don't call any of the code in the libraries, ALL of the symbols are being compiled into the App. 我已经使用otoolnm和其他工具进行了一些测试,可以看到,当我针对这些库中的任何一个进行链接时,即使我不调用库中的任何代码,所有符号也会被编译为该应用程序。 It takes my App from 42kB all the way to 3+MB. 它使我的App从42kB一直增长到3 + MB。

Any ideas on why this is happening? 为什么会这样?

Objective-C is a dynamic runtime; Objective-C是一个动态运行时; it is permissible eg to perform: 允许执行例如:

NSString *classToUse = ["MPViewController" stringByAppendingString:class];
return [[NSClassFromString(classToUse) alloc] init];

... and furthermore this is more or less exactly what happens when you load a NIB — string class and property names are loaded from disk, the backing classes are then found via the runtime and properties applied by key-value coding. ...而且,这或多或少与加载NIB时发生的情况完全相同-从磁盘加载字符串类和属性名,然后通过运行时和键值编码所应用的属性找到支持类。 So dynamic lookup is not an edge case. 因此,动态查找不是边缘情况。

A linker can therefore not make any assumptions about which symbols are used from an Objective-C static library, unlike eg a C linker. 因此,与C链接器不同,链接器不能对使用Objective-C静态库中的哪些符号做任何假设。

Yes,It can be done by stripping static libraries, but if post-processing is enabled. 是的,可以通过剥离静态库来完成,但是如果启用了后处理。 Set Xcode build setting "Deployment Postprocessing" to yes. 将Xcode构建设置“部署后处理”设置为“是”。 (DEPLOYMENT_POSTPROCESSING=YES). (DEPLOYMENT_POSTPROCESSING =是)。 Also make sure that "Use separate strip" is set to Yes. 还要确保将“使用单独的条”设置为“是”。 You can check this 你可以检查一下

You can also achieve what you are expecting by using Dynamic Library, there is a very nice article here 你也可以达到你通过使用动态库期待什么,有一个很不错的文章在这里

Extra Tip * While creating library set Debug Symbols to NO in your build settings. 额外提示*创建库时,在构建设置中将Debug Symbols设置为NO。 This can reduce the size of your static library by up to 30%. 这样最多可以将静态库的大小减少30%。

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

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