IOS 中cocopos的问题

解决 ld: library not found for -lPods的问题

  • 最近计划把公司的项目重构一下,第一步就是引入CocoaPods(以下简称pods)来管理第三方库。但是这第一步就不是太顺利。
    首先建好Podfile,并在命令行中输入pod install,结果报以下错误
[!] The XXX target overrides the 'OTHER_LDFLAGS' build setting defined in  
'Pods/Target Support Files/Pods/Pods.debug.xcconfig'.  
 This can lead to problems with the CocoaPods installation  
    - Use the '$(inherited)' flag, or
    - Remove the build settings from the target.



[!] The 'SubWayWifi [Release]' target overrides the 'OTHER_LDFLAGS' build setting defined in 
'Pods/Target Support Files/Pods/Pods.release.xcconfig'. 
This can lead to problems with the CocoaPods installation
    - Use the '$(inherited)' flag, or
    - Remove the build settings from the target.

现在打开有pods建好的workspace文件,尝试编译,会报ld: library not found for -lPods错误,原因就是工程里面的设置项覆盖了pods中xcconfig中的设置。解决办法就是在build setting->other linker flag中,加上$(inherited)即可。

OK,重新安装pod试试,由于我们已经进行过一次安装,所以本次只用更新一次即可,在命令行中输入pod update,现在没有报任何错误。但是当我尝试编译工程的时候,又报了一个错误:ld: library not found for -lReactiveCocoa。咋又找不到相应的第三方库了呢?好吧,继续查资料。

最后还是在cocoapods的官网Troubleshooting找到的解决办法。在Edit Scheme中,找到Build项,点击+号,找到Pods静态库,点击Add。再尝试编译,编译通过。

移除掉 -ObjC 亲测可用 但是 .a文件在编译的时候链接不上 这类问题是重复引起的 只要看xcode给的错误信息挨个删就可以了

错误信息

Try remove the “-ObjC” linker flag from the “Other Linker Flags” section of build settings.


遇到引用库重复定义的问题,需要解决。

项目需要,同时引用ZBar和QQ授权登录SDK,由于二者均使用了Base64处理数据,XCode编译时报错:
duplicate symbol _base64_encode in:
...\libzbar.a(symbol.o)
...\TencentOpenAPI(base64.o)

意思就是在这两个库中都定义了_base64_encode,编译器认为你重复定义了。至于为什么编译器认为重复定义,个人认为编译器编译全局变量时会根据名字进行编译,会把相同名称的全局变量编译为相同变量,也就是多个编译成一个,而编译器认为这样可能会引起错误,就提醒用户这里有错。

解决方案:
    参考了:http://blog.sina.com.cn/s/blog_4beb28f301012bl6.html
删掉了 set building->other linker flag-> -all_load

iOS的Framework是共享动态库,不会被打包到app中,非系统Framework静态库都会被打包到app中,所以会产生"Duplicate Symbol"的错误。
在Build Settings->Other link flags中删除所有的-all_load与-force_load, XCode会很smart的去掉"Duplicate Symbol"。


以下是从外国友人那获取的终极解决策略,方案是修改类库:
I'm going to assume that these are two third party libraries that have only provided you with the .a files and not the source code. You can use libtool, lipo and ar on the terminal to extract and recombine the files.
假设有两个三方类库仅提供给你了.a文件,没有源码,你可以通过libtool, lipo和ar在terminal中解压合并他们。
To see what architectures are in the file:
查看文件都支持了什么架构
$ lipo -info libTapjoy.a
Architectures in the fat file: libTapjoy.a are: armv6 i386

Then to extract just armv6, for example:
然后只解压armv6,例如
$ lipo -extract_family armv6 -output libTapjoy-armv6.a libTapjoy.a
$ mkdir armv6
$ cd armv6
$ ar -x ../libTapjoy-armv6.a

You can then extract the same architecture from the other library into the same directory and then recombine them like so:
你可以从另一个类库中解压同样架构的部分,然后将两者合并在一起
$ libtool -static -o ../lib-armv6.a *.o

And then finally, after you've done this with each architecture, you can combine them again with lipo:
如上所示,你可以将所有架构都按照这个流程走一遍,然后合并
$ cd ..
$ lipo -create -output lib.a lib-armv6.a lib-i386.a

This should get rid of any duplicate symbols, but will also combine the two libraries into one. If you want to keep them separate, or just delete the duplicate from one library, you can modify the process accordingly.
这个过程不仅解决掉了duplicate symbols的问题,也将两个类库合并为一个。如果你想分别保存两个类库,你可以将duplicate的部分从任意一个类库中删除,你可以相应的修改这个过程。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值