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

查看:827
本文介绍了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.

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

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来处理 relative 路径库?

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

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

for background information, see this question

推荐答案

使用Xcode 4 ,如果您将库项目包含到您的应用程序项目中,那么您可以将其添加到其他链接器标志:

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天全站免登陆