为什么在XCode 4.2中我的三个依赖项不再需要-force_load? [英] Why is -force_load no longer required for my three20 dependencies in XCode 4.2?

查看:145
本文介绍了为什么在XCode 4.2中我的三个依赖项不再需要-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),您遇到的问题之一是如何在该库中包含类别的符号,以便它们可供应用程序使用。链接器标志 -ObjC 应该提取足够的信息以包括这些构建框架中的类别,如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标志。

For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load or -force_load flags.

-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中我的三个依赖项不再需要-force_load?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆