What does the -all_load linker flag do?

64,301

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.

Share:
64,301
Guy Ephraim
Author by

Guy Ephraim

Software engineering expert

Updated on May 05, 2020

Comments

  • Guy Ephraim
    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
    Brad Larson about 14 years
    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.
  • Guy Ephraim
    Guy Ephraim about 14 years
    shouldn't there be some warnings or errors of the missing method at compile time?
  • Sophistifunk
    Sophistifunk almost 14 years
    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:"
  • Chris Hill
    Chris Hill almost 13 years
    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.
  • onigunn
    onigunn almost 12 years
    Hooking into this: is there a list of all Flags?
  • topwik
    topwik over 11 years
    Is it possible to specify -all_load for specific static references? like just for restKit?
  • Joel Fischer
    Joel Fischer over 10 years
    If only Apple would make dynamic frameworks available to developers, this wouldn't happen. WTF Apple.
  • Rob
    Rob over 10 years
    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.
  • Admin
    Admin over 10 years
    Using -all_load without -dynamic causes a warning in Xcode 5.1
  • Moisés Olmedo
    Moisés Olmedo about 10 years
    Using only -ObjC like Chris said worked when linking the Kal library
  • ThomasW
    ThomasW over 8 years
    Now -all_load and -force_load aren't even mentioned in the Tech Q&A.