什么是减少objective-c中静态库大小的最佳实践? [英] What are best practices to decrease the size of static libraries in objective-c?

查看:159
本文介绍了什么是减少objective-c中静态库大小的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建一个objective-c静态库时,我注意到.a文件(来自模拟器和iPhone的胖文件)非常大。特别是,它最初是5.7mb。我找到这篇文章并设置我的构建设置生成调试符号改为否,将lib大小减小到1.7mb。

In building an objective-c static library, I noticed that the .a file (fat file from simulator and iPhone) is quite large. In particular, it was originally 5.7mb. I found this post and set my build settings Generate Debug Symbols to No, decreasing the lib size to 1.7mb.

这是一个很大的改进,但还有什么可以做的吗?实现和头文件单独占用~100kb。

This was a big improvement, but is there anything else that can be done? The implementation and header files alone take up ~100kb.

推荐答案

如果它是您关注的一部分,静态库就是相关的.o文件一起存档加上一些簿记。因此,1.7mb静态库 - 即使其中的代码是整个1.7mb - 通常不会为您的产品增加1.7mb。关于死代码剥离的通常规则将适用。

In case it's part of your concern, a static library is just the relevant .o files archived together plus some bookkeeping. So a 1.7mb static library — even if the code within it is the entire 1.7mb — won't usually add 1.7mb to your product. The usual rules about dead code stripping will apply.

除此之外,您还可以减少代码的内置大小。以下可能不是一个全面的列表。

Beyond that you can reduce the built size of your code. The following probably isn't a comprehensive list.

在目标的构建设置中查找优化级别。通过将其切换为最快,最小的-Os,您将允许编译器牺牲一些大小的速度。

In your target's build settings look for 'Optimization Level'. By switching that to 'Fastest, Smallest -Os' you'll permit the compiler to sacrifice some speed for size.

确保您正在构建拇指,更多紧凑的ARM代码。假设您正在使用LLVM,这意味着确保您的项目设置中没有 -mno-thumb

Make sure you're building for thumb, the more compact ARM code. Assuming you're using LLVM that means making sure you don't have -mno-thumb anywhere in your project settings.

还要考虑要构建哪些体系结构。 Apple不允许提交支持ARMv6和iPhone 5屏幕的应用程序,并且完全从最新的Xcode中删除了ARMv6支持。所以在这一点上可能没有任何意义。

Also consider which architectures you want to build for. Apple doesn't allow submission of an app that supports both ARMv6 and the iPhone 5 screen and have dropped ARMv6 support entirely from the latest Xcode. So there's probably no point including that at this point.

这篇关于什么是减少objective-c中静态库大小的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆