About the other linker flags on Xcode

Source: Internet
Author: User

I. Description of the problem

Before a third-party static library. A, and then always prompt at run time

2015-06-14 15:38:33.135 brtexample[5890:695264]- [Cbuuid toString]: Unrecognized selector sent to instance 0x1742281c0

2015-06-14 15:38:33.135 brtexample[5890:695264] * * * terminating app due to uncaught exception ' Nsinvalidargumentexception ', Reason: '-[cbuuid toString]: Unrecognized selector sent to instance 0x1742281c0 '

First throw Call stack:

(0x1848942d8 0x1960680e4 0x18489b3a4 0x184898154 0X18479ACCC 0x100082d7c 0x18450319c 0x184500b3c 0x1844fc9d4 0x1000e8fd4 0x1000e8f94 0x1000f3db8 0x1000ec2c4 0x1000f65d4 0x1000f8248 0x19689922c 0x196898ef0 )

Libc++abi.dylib:terminating with uncaught exception of type NSException

Second, problem solving

There is a good chance that the Cbuuid category is added to the static library, so

targets option-build settings-Search Other linker flags, enter - all_load
Third, expand

Excerpt from (http://blog.sina.com.cn/s/blog_4cd8dd130102v47r.html)

targets option has the other linker flags set to fill in Xcode's linker parameters, such as:-O Bjc-all_ Load-force_load and so on.
Remember when we were learning C programs, the steps from C code to executable were:
source code > Preprocessor > Compiler > Assembler > Machine code > Linker > Executable
In the final step, you need to link the. o file to the C-language runtime. Use the LD command. After a series of processing of the source files, a corresponding. obj file is generated, and then a project will inevitably have many. obj files, and there will be a variety of connections between these files, such as function calls. The thing that the linker does is to link these target files with some of the libraries used to form a complete executable file.
If you want to look at what the linker has done, see: http://www.dutor.net/index.php/2012/02/what-linkers-do/

Then, the value set by other linker flags is actually the parameter that is added later when the LD command executes.

The following 3 common parameters are described individually:
-OBJC: When this parameter is added, the linker will load all the Objective-c classes and categories in the static library into the final executable file
-all_load: will let the linker load all the found target files into the executable file, but do not use this parameter arbitrarily! If you use more than one static library file, and then use this parameter, then you are likely to encounter ld:duplicate symbol error, because different library files may have the same target file, so it is recommended to use when encountering-OBJC failure-force_ The load parameter.
-force_load: What you do is exactly the same as-all_load, but-force_load needs to specify the path to the library file to be loaded completely, so you simply load a library file without affecting the rest of the library file's on-demand loading

After adding the library, Need to add the-OBJC flag to the other Linker flags in Xcode's build settings, which has not been used before, so I have specifically studied its role.

the use of this flag is related to an important feature of OBJECTIVE-C: category. As explained here, there are some conflicts between the standard static library implementation of UNIX and the dynamic nature of Objective-c: Objective-c does not define a link symbol for each function (or method), it creates a link symbol for each class. This way, when you use categories in a static library to extend an existing class, the linker does not know how to integrate the methods in the original class with the method in the category, causing you to invoke the method in the category with "selector not recognized", which means that the method definition error is not found. In order to solve this problem, the-OBJC flag is introduced, and its function is to load all the object-related files in the static library.



About the other linker flags on Xcode

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.