views:

192

answers:

1

Hi all.

I am confronted with the double bind, that 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 runtime 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 instant 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 coming to my mind either lead into xcode thinking its another linker flag instead of a parameter to the previous one, or the linker is throwing syntax related errors or the flag simply does nothing at all in comparison to not being set. I also opened the .pbxproj-file in a text-editor to edit it to the correct command line syntax manually, but when reloading the project with xcode, it auto changes the syntax into interpreting the parameter to force_load as a separate flag.

Anyone having an idea on this issue?

Thx, Kaiserludi.

A: 

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 tried also tried added 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.

par
Hmmmm, I have a library with categories. If I link it with all_load, everything is great. If I link it without all_load, it links OK, but on run it has errors when it tries to call category methods. If I link it with force_load directoryPath/release-iOS-internal-iphonesimulator/libraryname.a, I get a duplicate symbol error. The version I am building is the debug version; could that have anything to do with it?
William Jockusch
The force_load command is including your library. If you have a duplicate symbol error then you probably really do have a duplicate symbol in there somewhere. I'm not sure if this would cause a problem but is the library included as a member of your project and also via force_load? Maybe that makes a difference with categories. Do you have a category method with the same name already defined in your project somewhere? You can also look at the build results window in xcode, select 'show all messages', then pop down the link command to get the command line then go play with that in terminal.
par