Xcode -- 让 force_load 使用相对路径 [英] Xcode -- get force_load to work with relative paths

查看:12
本文介绍了Xcode -- 让 force_load 使用相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接到 Xcode 项目时,某些库需要 -all_load 链接器标志.但是,如果库之间存在符号冲突,这会导致链接器错误.解决方案是使用 -force_load,它可以有效地让您在某些库上使用 -all_load,但不能在其他库上使用.

Some libraries require the -all_load linker flag when linking to an Xcode project. However, this leads to a linker error if there are symbol conflicts among libraries. The solution is to use -force_load, which effectively lets you use -all_load on some libraries, but not on others.

但是,这反过来又导致了一个新问题,至少对我来说是这样.每当我将 -force_load 与库的 relative 路径一起使用时,链接器总是会发现库与其自身之间的符号冲突.看来链接器认为绝对路径的库和相对路径的库是不同的库,因此发现库和自身有冲突.

However, this in turn leads to a new problem, at least for me. Whenever I use -force_load with a relative path to a library, the linker always finds symbol conflicts between the library and itself. It appears that the linker thinks that the library with its absolute path and the library with its relative path are different libraries, and therefore finds conflicts between the library and itself.

我可以通过使用带有标志的 absolute 路径来避免这种情况.但这不是一个很好的解决方案,因为将库的源代码保存在我的文档目录中很方便.但是文档目录的路径在其他机器上会有所不同.

I can avoid this by using an absolute path with the flag. But this is not a wonderful solution, as it is convenient to keep source code for libraries within my documents directory. But the path to the documents directory will be different on other machines.

问题:任何人都可以让 force_load 使用库的相对路径吗?

Question: Can anyone get force_load to work with a relative path to the library?

有关背景信息,请参阅 这个问题

for background information, see this question

推荐答案

使用 Xcode 4,如果您将库项目包含到您的应用项目中,则可以将其添加到 Other Linker Flags:

With Xcode 4, if you include the library project into your app project, then you can add this to the Other Linker Flags:

-force_load $(BUILT_PRODUCTS_DIR)/<library_name.a>

你仍然需要依赖,你还需要将库添加到框架和库的链接阶段列表中.

You still need the dependency, and you need to add the library in the Link Phase list of frameworks and libraries too.

Apple 现在表示,从某些 Xcode 4 版本开始,您可以简单地使用此链接器标志:-ObjC"来获取具有正确加载类别的库.该标志在 Xcode 5 中对我来说工作得很好.人们仍在为这个答案投票,但我怀疑 -ObjC 标志现在是最好的解决方案.

Apple now says as of some Xcode 4 release that you can simply use this linker flag: "-ObjC" to get libraries with categories to properly load. That flag is working just fine for me in Xcode 5. People are still up voting this answer, but I suspect that the -ObjC flag is the best solution now.

这篇关于Xcode -- 让 force_load 使用相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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