132

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?

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
Guy Ephraim
  • 3,482
  • 3
  • 26
  • 30
  • 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 May 25 '10 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. – Guy Ephraim May 26 '10 at 13:24

1 Answers1

152

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sharjeel Aziz
  • 8,495
  • 5
  • 38
  • 37
  • 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 May 25 '10 at 17:54
  • 1
    shouldn't there be some warnings or errors of the missing method at compile time? – Guy Ephraim May 26 '10 at 13:18
  • 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:" – Sophistifunk Jul 23 '10 at 04:09
  • 16
    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 Aug 26 '11 at 23:04
  • Hooking into this: is there a list of all Flags? – onigunn Aug 08 '12 at 17:17
  • Is it possible to specify -all_load for specific static references? like just for restKit? – topwik Mar 21 '13 at 14:42
  • If only Apple would make dynamic frameworks available to developers, this wouldn't happen. WTF Apple. – Joel Fischer Jan 31 '14 at 21:10
  • 4
    According to http://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. – Liron Yahdav Feb 04 '14 at 19:33
  • Using -all_load without -dynamic causes a warning in Xcode 5.1 –  Mar 29 '14 at 05:22
  • Using only -ObjC like Chris said worked when linking the Kal library – Moisés Olmedo Apr 25 '14 at 00:35
  • 2
    Now `-all_load` and `-force_load` aren't even mentioned in the Tech Q&A. – ThomasW Feb 10 '16 at 01:08