Xcode -- 让force_load 使用相对路径
某些库在链接到 Xcode 项目时需要 -all_load 链接器标志。但是,如果库之间存在符号冲突,这会导致链接器错误。解决方案是使用 -force_load,它可以有效地让您在某些库上使用 -all_load,但不能在其他库上使用。
然而,这反过来又导致了一个新问题,至少对我来说是这样。每当我将 -force_load 与库的相对路径一起使用时,链接器总是会发现库与其自身之间的符号冲突。看来链接器认为具有绝对路径的库和具有相对路径的库是不同的库,因此发现库与自身之间存在冲突。
我可以通过使用带有标志的绝对路径来避免这种情况。但这不是一个很好的解决方案,因为将库的源代码保存在我的文档目录中很方便。但文档目录的路径在其他机器上会有所不同。
问题:任何人都可以让force_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.
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 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.
Question: Can anyone get force_load to work with a relative path to the library?
EDIT: for background information, see this question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Xcode 4,如果您将库项目包含到您的应用程序项目中,那么您可以将其添加到其他链接器标志中:
您仍然需要依赖项,并且还需要将库添加到框架和库的链接阶段列表中。
编辑:Apple 现在表示,从某些 Xcode 4 版本开始,您可以简单地使用此链接器标志:“-ObjC”来获取具有正确加载类别的库。该标志在 Xcode 5 中对我来说工作得很好。人们仍在投票这个答案,但我怀疑 -ObjC 标志是现在最好的解决方案。
With Xcode 4, if you include the library project into your app project, then you can add this to the Other Linker Flags:
You still need the dependency, and you need to add the library in the Link Phase list of frameworks and libraries too.
EDIT: 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.
这对我有用。像上面的答案一样,您仍然需要将库包含在项目中。
对于路径,它只是项目中指向您放置库的位置的文件夹,例如 BaseFoler/Subfolder/libName.a。
This worked for me. Like the above answers you still need to include the library in the project.
For the path it's just the folders in your project that lead to where you put your library, for example BaseFoler/Subfolder/libName.a.