Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 577
William Jockusch Avatar asked Jan 24 '11 21:01

William Jockusch


1 Answers

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.

like image 90
David H Avatar answered Oct 13 '22 09:10

David H