-All_load option when compiling iOS program, and-all_load issues caused by ld duplicate symbol xx, ios-all_load

Source: Internet
Author: User

-All_load option when compiling iOS program, and-all_load issues caused by ld duplicate symbol xx, ios-all_load

When debugging the Baidu map application in the new SDK environment, the app always unexpectedly exits. The reason why the error was found for half a day is the error of unrecognized selector xx, in addition, an Unknown class XXX in Interface Builder file error is reported, and Baidu official information is retrieved. The official suggestion is to add the-all_oad option to the Other Linker Flags in the Build Settings of the app, however, other static libraries are connected to my app. After this option is added, the ld duplicate symbol xx error is reported during compilation, so I went to the Apple official website to find the information, we found that there is a similar feature option-ObjC. After you change-all_load to-ObjC in the compilation option, the app compilation and running are very common. The following is an official introduction from apple:

Https://developer.apple.com/library/mac/#qa/qa2006/qa1490.html

The official note is that the static library linked to the app uses Category (Category). When compiled to the static library, these code modules actually exist in different obj files. When the program connects to the Category method, it actually only loads the Category module, and the extended basic class code is not loaded. In this way, although the program can be compiled, the unrecognized selector error will occur during runtime because the base class module cannot be found. -All_load is used to solve the above problem. For example, you can use-force_load and-ObjC. A related document is attached:

Http://stackoverflow.com/questions/2300867/how-can-i-avoid-duplicate-symbol-errors-in-xcode-with-shared-static-libraries/2300873#2300873

Another explanation:

-ObjC

This flag tells the linker to load the Objective-C class and Category defined in the library. In this way, the compiled app will become larger (because other objc code is loaded ). However, if the static library contains classes and category, you only need to add this flag.

-All_load

This flag specifically handles a bug of-ObjC. After-ObjC is used, if the class library contains only category and no class, the category cannot be loaded. The work und is to add-all_load or-force-load. -All_load forces the linker to load all target files, even if there is no objc code. -Force_load is available after xcode3.2. But-force_load must be followed by a path that only wants the static library.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.