Avoid duplicate symbol in static library and its customer

发布static library给使用者使用。在实际的工程实践中,iOS静态库一般会在对外/对内提供SDK时出现。

静态库(SDK)本身可能依赖一些第三方的库,当使用该SDK的App也依赖了同样的第三方库,那么问题就来啦。

Figure: SDK 和 SDK Customer 依赖相同的3rd library

1. static library如何避免和使用者的代码有重复符号

Ref[1] Ref[4]

2. 从iOS的静态库中抽取出object file

Ref[5]

 $ lipo libXXXSDK.a -thin armv7 -output libXXXSDK-armv7.a
$ ar -x libXXXSDK-armv7.a

3. 发布静态库

3.1 发布支持模拟器和真机的静态库

Ref[6] Ref[7]

3.2 debug编译和release编译的静态库区别

A: NSLog

debug: NSLog会输出

release: NSLog不会输出

3.3 如何strip静态库的符号表

A) 隐藏静态库的符号

Ref[17]

" Hiding internal names requires a few simple Xcode build settings, and it is not generally

necessary to modify source or change the type of the built product.

1. Eliminate any internal symbols required between modules by performing a single-object prelink.

Set the Xcode build setting named "Perform Single-Object Prelink" to Yes (GENERATE_MASTER_OBJECT_FILE=YES).

This causes ld to be run with the "-r" flag.

2. Make sure that the setting "Strip Style" is set to "Non-global symbols" (STRIP_STYLE=non-global), this passes "-x" to ld.

Stripping is only actually performed on static libraries if post-processing is enabled (and this is not the default).

3. Set Xcode build setting "Deployment Postprocessing" to yes. (DEPLOYMENT_POSTPROCESSING=YES).

Also make sure that "Use separate strip" is set to Yes (not always the default).

4. If, in addition to local symbols, if you need to remove some of the global symbols you can supply additional

options to the strip command, under the Xcode build setting "Additional strip flags". E.g. I commonly

use the strip "-R somefile" option to provide a file with an additional list of symbols which I want removed

from the global symbol table." Ref[17]

关于"STRIP_SYTLE" 参考Ref[19]

B) 将静态库的符号表剔除后, 会出现这种情况: 静态库出现crash时,无法将地址符号化。Ref[18]

C) 那么静态库的符号被strip掉后, 会不会像App被生成.dSYM文件呢? 或者其他类似的东西?

3.4 自动构建多architecture的静态库

Ref[15]

3.5 当发布商业的静态库时,选择debug configuration 还是release configuration呢?

Ref[16]


Reference

1. Avoiding dependency collisions in iOS static library managed by CocoaPods  (AAAA+)

http://blog.sigmapoint.pl/avoiding-dependency-collisions-in-ios-static-library-managed-by-cocoapods/

https://github.com/jverkoey/nimbus/blob/master/scripts/generate_namespace_header

Bash, Perl or Sed, Insert on New Line after found phrase

http://stackoverflow.com/questions/6761796/bash-perl-or-sed-insert-on-new-line-after-found-phrase

2. Using Static Libraries in iOS

https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/creating.html

3. UNIX ar Examples: How To Create, View, Extract, Modify C Archive Files (*.a)

http://www.thegeekstuff.com/2010/08/ar-command-examples/

4. Avoiding duplicate symbol errors during linking by removing classes from static libraries  (ToRead)

http://atnan.com/blog/2012/01/12/avoiding-duplicate-symbol-errors-during-linking-by-removing-classes-from-static-libraries

5. Extract object (*.o) files from an iPhone static library

6. How to build a library for both iPhone simulator and device?

7. Build fat static library (device + simulator) using Xcode and SDK 4+

8. Distributing your Static Library

http://www.akitaonrails.com/2011/04/24/objective-c-distributing-your-static-library#.VZY4ShOqqko

9. Xcode 6 drops armv7s

https://www.cocoanetics.com/2014/10/xcode-6-drops-armv7s/

10. iOS Static Libraries Are, Like, Really Bad, And Stuff  (ToRead)

http://landonf.org/code/ios/Radar_15800975_iOS_Frameworks.20140112.html

11. Strip debug symbol from universal static libraries (tested for iOS only)

https://gist.github.com/neonichu/1662881

12. An XCode project template to build universal frameworks (arm7, arm7s, and simulator) for iOS / iPhone.

https://github.com/kstenerud/iOS-Universal-Framework

13. http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial (AAAA+)

14. strip nmeidt symbols: 编辑符号的工具

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/symbols.1.html

15. Automatic build of static library for iOS and many architectures (AAAA+)

http://blog.sigmapoint.pl/automatic-build-of-static-library-for-ios-for-many-architectures/

16. How to distribute Static libraries?

http://stackoverflow.com/questions/5730432/how-to-distribute-static-libraries/5778007#5778007

"So, long story short : just distribute a fat, release version of your library !"

17. strip symbol in static library

17.1 Symbol hiding in static libraries built with Xcode/gcc

17.2 Symbolification: Shipping Symbols

http://bdunagan.com/2010/05/15/symbolification-shipping-symbols/

17.3 How to solve symbolication problems --> "Build settings for getting proper symbol data"

http://support.hockeyapp.net/kb/client-integration-ios-mac-os-x/how-to-solve-symbolication-problems

17.4 xcode build settings for debug symbol

http://jonathanblog2000.blogspot.tw/2013/07/xcode-build-settings-for-debug-symbol.html

18. Symbolicating crash log for app with static library

19. Xcode Build Setting Reference

https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html

https://developer.apple.com/library/mac/technotes/tn2004/tn2123.html#SECNOSYMBOLS

iOS.StaticLibrary.1-avoid-duplicate-symbol-in-static-library[draft]的更多相关文章

  1. [问题]编译报错:clang: error: linker command failed with exit code 1及duplicate symbol xxxx in错误解决方法之一

    今天添加了一个新类(包括m,h,xib文件),还没有调用,-编译遇到如下错误,根据错误提示, duplicate symbol param1 in: /Users/xxxx/Library/Devel ...

  2. [报错]编译报错:clang: error: linker command failed with exit code 1及duplicate symbol xxxx in错误解决方法之一

    今天添加了一个新类(包括m,h,xib文件),还没有调用,—编译遇到如下错误,根据错误提示, duplicate symbol param1 in: /Users/xxxx/Library/Devel ...

  3. iOS开发 - OC - duplicate symbol _OBJC / undefind symbol 错误的相关处理

    前言: 作为一个iOS开发,相信大家都会遇到类似于 “duplicate symbol” 的程序报错. 对于很多新手来说,可能会有点手足无措,因为这种类型的报错一般并非是代码的逻辑错误,大部分情况下是 ...

  4. iOS程序开发引用的第三方库之间出现duplicate symbol时的处理方法

    iOS程序集成的第三方库过多时,很容易出现某几个库同时用到了一样的函数库,也就是在你的程序link时会提示duplicate symbol,而重复的符号又不是由你自己程序的代码造成的,也就说没法通过直 ...

  5. iOS开发 引用第三方库出现duplicate symbol时的处理方法

      该篇文章是我自己从我的新浪博客上摘抄过来的, 原文链接为: http://blog.sina.com.cn/s/blog_dcc636350102wat5.html     在iOS开发中, 难免 ...

  6. 【原】IOS合并lib(.a)库的终极可用方法(可用于解决duplicate symbol静态库冲突)

    网上流传了太多关于合并lib库的方法,自己也尝试过,但大多失败.有感于这种急于解决问题,经过百般尝试后依旧无果的无奈心情,小翁在这里用一个实例来完整阐述如何在mac中合并lib静态库. 这里以移动广告 ...

  7. iOS 解决一个因三方静态库冲突产生的duplicate symbol的问题

    最近在开发项目时编译三方.a时出现了冲突,原因是存在duplicate symbol. <1>模拟器编译时,应用的即时通讯模块采用的三方库(容联云),和视频监控模块采用的三方库(海康威视) ...

  8. 编译iOS程序时的-all_load选项,以及-all_load 导致的 ld duplicate symbol xx的问题

    在新的SDK环境中调试百度地图的应用程序时,app总是意外退出,找了半天发现错误的原因是unrecognized selector xx的错误,另外还有报了一个Unknown class XXX in ...

  9. iOS开发- &quot;duplicate symbol for architecture i386&quot; 解决的方法

    今天整合项目的时候, 遇到了这样一个问题. duplicate symbol _flag in: /Users/apple/Library/Developer/Xcode/DerivedData/bl ...

随机推荐

  1. Shiro 整合SpringMVC 并且实现权限管理

    Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Security做的功能强大 ...

  2. visual.studio.15.preview5 编译器

    前段时间微软更新了新版开发工具visual studio 15 preview5,安装后连文件结构目录都变了,想提取编译器还找不到. 不是原来的VC\BIN目录,已迁移到IDE\MSVC\14.10. ...

  3. 黄聪:No 'Access-Control-Allow-Origin' header is present on the requested resource解决办法

    在.htaccess文件里面添加下面代码: <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*& ...

  4. 基于adt-bundle-windows-x86的android开发环境搭建

    0,简介: 最近简单着手了解 android 开发.工欲善其事,必先利其器. 我本人不太喜欢使用java 开发,所以简单了解了下其 c# c++都可以进行android 开发,用c++的话要使用NDK ...

  5. 每天一个 Linux 命令(5):rm 命令

    昨天学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和目录的命令: rm命令.rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所 ...

  6. HttpURLConnection 直接发送soap消息调用webservice

    httpConn = (HttpURLConnection) new URL(urlString).openConnection();    httpConn.setRequestProperty(& ...

  7. CentOS 7 yum安装Zabbix

    一.Zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统 ...

  8. Flex中设置Camera的视频清晰质量的最佳配合

    今天需要设置Flex中的Camera组件的一些属性,后来发现清晰度不是很高,于是捣鼓了上午半天,设置了很多的参数,竟然发现手册上就是有现成的一些设置方法,郁闷!不过我还是专门设置了几个有用和必要的属性 ...

  9. 剑指offer习题集1

    1.打印二叉树 程序很简单,但是其中犯了一个小错误,死活找不到,写代码要注意啊 这里左右子树,要注意是node->left,结果写成root->left vector<int> ...

  10. vs2010中将c++控制台程序修改成windows应用程序

    报错:无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用 vs2010环境下将Win32控制台应用程序,改为Win32项目 直接将控制台的mian函数改成 _ ...