开发者

xcode project-/target-settings-syntax for linker flag force_load on iPhone

I am confronted with the double bind. On the one hand, for one of the 3rd party static libraries my iPhone application uses, the linker flag -all_load has to be set in the application project or target settings. Otherwise, the app crashes at run-time not finding some symbols called internally from the lib. On the other hand, for another 3rd party static lib, -all_load must not be set on application level, or the app won't build thanks to a "duplicate symbols" linker error.

To solve this issue, I now want to use force_load instead of load_all, as it due to documentation it does the same like all_load, but only for the passed path or lib-file, instead of all libs.

The problem with force_load is, I do not have a clue how to pass a path or file as parameter with it, when passing it via XCode project- or target-settings. All syntax-possibilities I tried either lead xcode to thinking it's another linker flag instead of a parameter to the previous one, or the linker throwing syntax related errors, or the flag simply does nothing at all.

I also opened the .pbxproj-file in a text-editor to edit it to the correct command line syntax manually. But when reloading the pr开发者_如何学Pythonoject with XCode, it auto-changes the syntax into interpreting the parameter to force_load as a separate flag.

Anyone have an idea on this issue?


I just tried this. I've compiled a static armv6, armv7, and i386 fat binary of PCRE for use in my iPhone project. My project normally just has my library added to the project and that links fine. So I unchecked the target membership box for libpcre.a and rebuilt. As expected, I get a bunch of missing symbol linker errors for the pcre symbols. Then I opened the target settings window and edited the "Other Linker Flags" section. I added:

-force_load lib/pcre/libpcre.a

The lib directory is in the same directory as my project.xcodeproj file.

It linked fine so I know the force_load command worked (and I can see it added to the build flags when xcode builds the file).

Hope that helps.

Update:

I also tried adding a system library to the "Other Linker Flags" line like so:

-force_load src/pcre/libpcre.a -force_load ${SDKROOT}/usr/lib/libz.dylib

That worked too.


I just added force_load to our project and all is fine using the simplest syntax possible. The library is a dependency built in the same project. The library is therefore included on the link command-line twice: once as a normal input file and once as an argument to -force_load. You might want to put quote characters around the argument.

In fact, I've even got this working using configuration-dependent settings (because the path is obviously different for debug vs. release and device vs. simulator).

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜