当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Xcode -- get force_load to work with relative paths

问题描述:

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

网友答案:

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.

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: