Xcode 多个静态库和重复符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13812007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode Multiple Static Libraries and Duplicate Symbols
提问by seanoshea
I'm developing an iPad application which relies on two static utility libraries (libBFSDK & libBetfair-Platform). Both static libraries include AFNetworking. When I try to include the two static libraries in my iPad application, I get a linking error like:
我正在开发一个 iPad 应用程序,它依赖于两个静态实用程序库(libBFSDK 和 libBetfair-Platform)。两个静态库都包含 AFNetworking。当我尝试在 iPad 应用程序中包含这两个静态库时,出现如下链接错误:
duplicate symbol _OBJC_METACLASS_$_AFImageCache in:
/Users/osheas/Library/Developer/Xcode/DerivedData/Betfair-gnnjnwtovdmtoxakuxbjyvetciyy/Build/Products/Debug-iphonesimulator/libBFSDK.a(UIImageView+AFNetworking.o)
/Users/osheas/Library/Developer/Xcode/DerivedData/Betfair-gnnjnwtovdmtoxakuxbjyvetciyy/Build/Products/Debug-iphonesimulator/libBetfair-Platform.a(UIImageView+AFNetworking.o)
ld: 86 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
UIImageView+AFNetworking is part of AFNetworking. Both static libraries include AFNetworking. As a result, I get duplicate symbols for UIImageView+AFNetworking.
UIImageView+AFNetworking 是 AFNetworking 的一部分。两个静态库都包含 AFNetworking。结果,我得到了 UIImageView+AFNetworking 的重复符号。
Anyone have ideas on a workaround for this? I have access to the source code for the two static libraries, but I'm still not sure how to solve this problem.
任何人都对此有解决方法的想法?我可以访问两个静态库的源代码,但我仍然不确定如何解决这个问题。
Thanks & please let me know if you need any other details,
谢谢,如果您需要任何其他详细信息,请告诉我,
Sean
肖恩
PS - FWIW I'm running Xcode 4.5 & I need to be able to deploy to iOS 4.x devices.
PS - FWIW 我正在运行 Xcode 4.5 & 我需要能够部署到 iOS 4.x 设备。
回答by Nate T
Since you have access to the source for the static libs, you could use the preprocessor to rename the AFNetworking symbols to something unique.
由于您可以访问静态库的源代码,您可以使用预处理器将 AFNetworking 符号重命名为唯一的名称。
Add flags for each duplicate symbol to your "Other C Flags" build setting with the format
使用以下格式将每个重复符号的标志添加到“其他 C 标志”构建设置中
-AFNetworkingSymbol=UniqueAFNetworkingSymbol
-AFNetworkingSymbol=UniqueAFNetworkingSymbol
This will still result in duplicate code, but should allow you to have multiple copies of AFNetworking without modifying the source.
这仍然会导致重复代码,但应该允许您拥有多个 AFNetworking 副本而无需修改源代码。
Ideally, most open source Obj-C code will move to solutions like CocoaPods and just specify dependencies instead of bundling them.
理想情况下,大多数开源 Obj-C 代码将转移到 CocoaPods 之类的解决方案,并且只指定依赖项而不是捆绑它们。
回答by Theis Egeberg
This is the simplest solution I have seen to this problem. I have tested it and it works. http://blog.sigmapoint.pl/avoiding-dependency-collisions-in-ios-static-library-managed-by-cocoapods/
这是我见过的最简单的解决方案。我已经测试过它并且它有效。 http://blog.sigmapoint.pl/avoiding-dependency-collisions-in-ios-static-library-managed-by-cocoapods/
回答by seanoshea
Apparently, this is a relatively common occurrence. See https://github.com/square/PonyDebugger/issues/36for more details.
显然,这是一个比较普遍的现象。有关更多详细信息,请参阅https://github.com/square/PonyDebugger/issues/36。
回答by Chu Chau
you check _AFImageCache has tow file in your project and remove one.
您检查 _AFImageCache 在您的项目中有两个文件并删除一个。
this can help you.
这可以帮助你。