本文介绍了为什么 XCode 4.2 中的 Three20 依赖项不再需要 -force_load?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目依赖于第三方静态库和 Three20 库.在 XCode 3.X 中,为了让我的项目能够编译,我必须在其他链接器标志"构建设置中使用 -force_load 标志,并指定我想要包含的三个 20 个库中的每一个.

I have project with a dependency on a third-party static library and the three20 libraries. In XCode 3.X, in order to get my project to compile, I had to use the -force_load flag in the "Other Linker Flags" build setting, and specify each of the three20 libraries that I wanted to include.

尝试在 XCode 4.2 中构建存档时,出现重复符号"错误.我通过删除七个单独的 -force_load 标志解决了这个问题,这些标志引用了我依赖的三个 20 库中的每一个.

When attempting to build an archive in XCode 4.2, I was getting a "duplicate symbol" error. I resolved this by removing the seven separate -force_load flags that referred to each of the three20 libraries on which I had a dependency.

我的项目现在成功构建.

My project now builds successfully.

我想知道是否有人可以向我解释为什么此更改有效?XCode 4.2 是否修复了错误,还是行为发生了变化?这篇文章暗示 XCode 3.2 中存在一个错误,但如果有人可以为我进一步阐明这个主题,那就太好了,这样我就可以确定我没有通过删除这些 -force_load 标志而可能做错了什么.

I wonder if someone can explain to my why this change worked? Was there a bug that XCode 4.2 fixed, or is the a behavioral change? This post suggests there was a bug in XCode 3.2, but it would be great if someone could shed additional light on this topic for me so I can be sure I haven't potentially done something wrong by removing these -force_load flags.

谢谢!

推荐答案

在构建静态库(如 iOS 所需)时,您会遇到的问题之一是如何在该库中包含类别中的符号,以便它们可由应用程序重新使用.正如 Dave Dribin 在他的文章 .

When building a static library (as required for iOS), one of the issues you'll encounter is how to include symbols from categories in that library so they're usable by an application. The linker flag -ObjC should pull in enough information to include categories in these built frameworks, as Dave Dribin describes in his article here.

然而,在 iPhone OS 2.0 和 3.0 之间,这停止正常工作.正如我在这个答案中提到的,我们在Core Plot框架中遇到了这个问题,发现需要添加-all_load链接器标志才能让框架正常工作.Apple 自己发布了 技术问答 QA1490,其中提到了这一点问题:

However, between iPhone OS 2.0 and 3.0, this stopped working right. As I mentioned in this answer, we encountered this problem in the Core Plot framework and found that we needed to add the -all_load linker flag to make the framework work right. Apple themselves posted Technical Q&A QA1490 which mentions this issue:

对于 64 位和 iPhone OS 应用程序,存在链接器错误防止 -ObjC 从静态库加载对象文件只包含类别而没有类别.解决方法是使用-all_load 或 -force_load 标志.

-all_load 强制链接器从它看到的每个存档中加载所有目标文件,即使是那些没有 Objective-C 代码的文件.-force_load 是在 Xcode 3.2 及更高版本中可用.它允许更细粒度的控制存档加载.每个 -force_load 选项后必须跟一个路径一个存档,并且该存档中的每个目标文件都将被加载.

-all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load option must be followed by a path to an archive, and every object file in that archive will be loaded.

不幸的是,这样做的副作用是从多个库中链接的重复符号可能会导致您遇到的错误.

Unfortunately, the side effect of this is that duplicate symbols linked in from multiple libraries can cause errors like the ones you experienced.

我提交了一份关于此的错误报告(早在 2009 年),现在 Xcode 中使用的最新版本的 LLVM 似乎不再受此链接器错误的影响.我尝试将 -ObjC 与 Core Plot iOS 静态库目标一起使用,现在工作正常.这是个好消息.

I filed a bug report about this (back in 2009), and it appears that the latest version of LLVM now used in Xcode no longer suffers from this linker bug. I tried just using -ObjC with the Core Plot iOS static library target and it works fine now. That's welcome news.

这篇关于为什么 XCode 4.2 中的 Three20 依赖项不再需要 -force_load?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 09:18