135

I can't find anywhere what the -all_load flag does when compiling Objective-C code.

I have some issues uploading binaries to Apple. They say it's because I didn't use this flag. However, my code compiles even without it.

Can someone help me with this?

2
  • 2
    Typically, any errors you see with this occur on the device when running the application. Are you saying that you didn't test your application on actual hardware before submission for review by Apple? If so, that's a very, very bad idea.
    – Brad Larson
    Commented May 25, 2010 at 17:51
  • I've tested it, however my "distribution" configuration - the one with the app store provisioning profile - didn't had the flag and all of the tests were done using the development profile which had the flag so everything seems ok, and when I compiled it for the app store with the distribution profile the flag was off, and because the distribution profile can't be installed locally i couldn't check it. Commented May 26, 2010 at 13:24

1 Answer 1

155

It is probably related to this technical note https://developer.apple.com/library/content/qa/qa1490/_index.html

IMPORTANT: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load or -force_load flags. -all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load option must be followed by a path to an archive, and every object file in that archive will be loaded.

11
  • 3
    Yes, this primarily comes into play with static libraries for the iPhone. If they are compiled without this linker flag, the categories are not included in the built binary and any application using these static libraries will have runtime errors when executed on iPhone OS hardware.
    – Brad Larson
    Commented May 25, 2010 at 17:54
  • 18
    No, because the categories exist at compile-time, they're just not being linked into the final binary. But because of the dynamic nature of Obj-C dispatches, the linker doesn't point calling code directly to the implementing method, so it never notices that it's missing. Then at runtime, you get the kaboom, the same as if you'd called it using "-performSelector:" Commented Jul 23, 2010 at 4:09
  • 17
    Just want to clarify the technical note: Most of the time you'll want the -ObjC linker flag, not -all_load. -all_load is recommended in the (i'd assume rare) instance where you have a library with no classes, just categories.
    – Chris Hill
    Commented Aug 26, 2011 at 23:04
  • 4
    According to stackoverflow.com/a/2615407/62 this has been fixed as of XCode 4.2, so you don't need the -all_load or -force_load flags anymore. You do still need -ObjC. Commented Feb 4, 2014 at 19:33
  • 2
    Now -all_load and -force_load aren't even mentioned in the Tech Q&A.
    – ThomasW
    Commented Feb 10, 2016 at 1:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.