ld:在 iOS 4.3 上有重复符号 _objc_retainedObject ,但在 iOS 5.0 上没有

发布于 2024-12-19 13:56:04 字数 728 浏览 2 评论 0 原文


一些背景 - 我已经使用 Diney 的指南构建了一个自定义框架 http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/

它是为 armv6 / armv7 构建的,它是基于ARC的框架,以4.3的部署目标编译。

当我将生成的框架放入 5.0 项目时,效果很好,但是当我将其放入 4.3 项目(ARC 或非弧,无关紧要)时,我得到以下内容,但我无法真正理解......

我'我还尝试手动添加 libarclite.a 但它没有改变任何东西。

ld:架构armv7的/Users/freak4pc/Project/MyFramework.framework/MyFramework和/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a(arclite.o)中存在重复符号_objc_retainedObject 命令 /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang 失败,退出代码 1

希望对此提供任何帮助。
谢谢

Some background - I've built a custom Framework using Diney's guide at http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/

Its built for both armv6 / armv7 , its an ARC-based framework, compiled with a depolyment target of 4.3.

When i put the resulting framework in a 5.0 project it works great, but when i put it in a 4.3 project (ARC or non-arc, doesnt matter), i get the following which i can't really understand ...

I've also tried adding libarclite.a manually but it didn't change anything.

ld: duplicate symbol _objc_retainedObject in /Users/freak4pc/Project/MyFramework.framework/MyFramework and /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a(arclite.o) for architecture armv7
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang failed with exit code 1

Would appreciate any help on this.
Thanks
Shai

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光下慵懒的猫 2024-12-26 13:56:04

我正在努力解决同样的问题。解决方法是将框架的部署目标设置为 iOS5(不过请检查这是否不会产生其他问题)。

那么如果面向 iOS4,您必须在主项目中使用 ARC,否则 libarclite 将丢失。我的解决方案是提供两个框架,具体取决于它们是否使用 ARC。

以下是苹果开发论坛的两个链接,其中包含更多信息:
https://devforums.apple.com/message/539344#539344

https://devforums.apple.com/message/588316#588316

更新:
有一个更好的方法。只需使用 iOS5 最低目标构建静态库,然后手动添加 /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a (和 /Developer/usr/lib/arc/libarclite_iphonesimulator.a),如果您项目使用ARC并且需要iOS4支持。

更新2:实际上,只需使用链接器标志 -fobjc-arc ;这会将 libarclite 与该库链接(如果该库尚未存在)。最佳解决方案。

I'm struggling with the same problem. The workaround is so set the deployment target of your framework to iOS5 (check if that doesn't make other problems though).

Then you must use ARC in the master project if targeting iOS4, else libarclite will be missing. My solution will be to supply two frameworks, depending if they use ARC or not.

Here's two links to Apple's dev forum with a little bit more info:
https://devforums.apple.com/message/539344#539344

https://devforums.apple.com/message/588316#588316

Update:
There is a better way. Just build your static library with iOS5 minimum target, and manually add /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a (and /Developer/usr/lib/arc/libarclite_iphonesimulator.a) if your project is not using ARC and needs iOS4-support.

Update 2: Actually, just use the linker flag -fobjc-arc ; this will link libarclite with the library if it's not already in there. Best solution.

情仇皆在手 2024-12-26 13:56:04

哇,这是一次艰难的旅程,但我终于解决了!

引发最终想法的是@steipete 的评论,
这是一个有点复杂的情况,所以我会尽力向可能也遇到过这个问题的人解释一下。

  1. 在 iOS 4.3 上编译启用 ARC 的框架会自动将 libarclite.so 附加到“桥接”4.3 ARC 与 5.0 ARC。当这个框架导入到 4.3 项目时,arclite 实际上被链接了两次 - 一次用于框架(即 4.3),一次用于项目本身 - 这导致了“重复符号”错误,这意味着框架必须在5.0,项目可以是4.3。但然后;
  2. 我的框架使用 @mattt 的 AFNetworking 来执行 HTTP 请求和不同 API 的 JSON 解析。 AFNetworking 在编译时自动检查您的目标是否为 iOS5,如果是,则使用 NSJSONSerialization,否则它将回退到任何导入的 JSON 库,例如 JSONKit。
  3. 当为 iOS5 编译支持 AFNetworking 的框架时(为了避免问题 1),它会自动附加 NSJSONSerialization,这将导致 4.3 项目出现异常,这意味着您必须手动查找编译方向并在编译之前删除对 NSJSONSerialization 的调用,因此它会自动回退到 4.3 兼容库(在我的例子中为 JSONKit)。在 AFHTTPClient.m 和 AFJSONRequestOperation.m 上找到了该编译条件(例如 #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6
  4. 删除这些条件后,我成功地使用 JSONKit 编译了 iOS5 框架的NSJSONSerialization,并成功地能够在我的iOS4.3项目中使用它。

希望这能帮助任何像我一样可能为此困扰几天的人:)

Shai。

Wow that was a hard ride but i finally solved it!

What sparked the final idea was @steipete's comment ,
Its a bit of a complex situation so i'll try to explain it for anyone who might've crossed this issue as well.

  1. Compiling a ARC-enabled framework on iOS 4.3 will automatically attach libarclite.so to "bridge" 4.3 ARC with 5.0 ARC. When this framework was imported to a 4.3 project, arclite was actually linked twice - once for the framework (which is 4.3), and once for the project itself - which caused the "duplicate symbol" error, meaning the framework has to be compiled on 5.0, and the project can be 4.3. But then ;
  2. My framework is using @mattt 's AFNetworking to perform HTTP Requests and JSON parsing of different APis. AFNetworking automatically checks while compiling if your target is iOS5 , and if it is, it uses NSJSONSerialization, otherwise it would fall back to any imported JSON library such as JSONKit.
  3. When compiling my AFNetworking-enabled Framework for iOS5 (to avoid problem no.1), it would automatically attach NSJSONSerialization, which will cause an exception on 4.3 projects, meaning you would have to manually look for the compile directions and remove the calls to NSJSONSerialization before compiling, so it would automatically fall back to the 4.3-compatible library (in my case JSONKit) . That compilation condition is found on AFHTTPClient.m and AFJSONRequestOperation.m (e.g. #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6)
  4. After removing those conditions, i successfully compiled my framework for iOS5 with JSONKit instead of NSJSONSerialization, and was successfully able to use it in my iOS4.3 project.

Hope this would help anyone else who might struggle with this for a couple of days like myself :)

Shai.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文