What does the -all_load linker flag do?
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.
![Guy Ephraim](https://i.stack.imgur.com/hABsv.jpg?s=256&g=1)
Comments
-
Guy Ephraim about 4 years
I can't find anywhere what the -all_load flag do when compiling Objective-C code.
I have some issues uploading binaries to Apple, the they say it's because I didn't use this flag, but my code compiles even without it.
Can some one help me with that?
Thanks
-
Brad Larson about 14 yearsYes, 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.
-
Guy Ephraim about 14 yearsshouldn't there be some warnings or errors of the missing method at compile time?
-
Sophistifunk almost 14 yearsNo, 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:"
-
Chris Hill almost 13 yearsJust 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.
-
onigunn almost 12 yearsHooking into this: is there a list of all Flags?
-
topwik over 11 yearsIs it possible to specify -all_load for specific static references? like just for restKit?
-
Joel Fischer over 10 yearsIf only Apple would make dynamic frameworks available to developers, this wouldn't happen. WTF Apple.
-
Rob over 10 yearsAccording 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.
-
Admin over 10 yearsUsing -all_load without -dynamic causes a warning in Xcode 5.1
-
Moisés Olmedo about 10 yearsUsing only -ObjC like Chris said worked when linking the Kal library
-
ThomasW over 8 yearsNow
-all_load
and-force_load
aren't even mentioned in the Tech Q&A.