Xcode -- 获取 force_load 以使用相对路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4787279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:08:12  来源:igfitidea点击:

Xcode -- get force_load to work with relative paths

iphonexcodeioslinkerstatic-libraries

提问by William Jockusch

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.

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

However, this in turn leads to a new problem, at least for me. Whenever I use -force_load with a relativepath 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.

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

I can avoid this by using an absolutepath 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?

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

EDIT: for background information, see this question

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

回答by David H

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

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

-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.

您仍然需要依赖项,并且您还需要在框架和库的链接阶段列表中添加库。

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.

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

回答by Theris10

This worked for me. Like the above answers you still need to include the library in the project.

这对我有用。像上面的答案一样,您仍然需要在项目中包含库。

-force_load $(SRCROOT)/pathToLibraryFromProject/libname.a

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.

对于路径,它只是指向您放置库的位置的项目中的文件夹,例如 BaseFoler/Subfolder/libName.a。