Static Library Dynamic Library

Source: Internet
Author: User

1, Existence form

Static libraries:. A and. Framework;

Dynamic libraries:. Dylib and. Framework;

2. Use

Static Library: When the link, the static library will be fully copied to the executable file, the multiple use of multiple copies of redundant copies; --(Core code, package MRC into a static library to avoid switching the development environment)

Dynamic libraries: When linking, do not copy, the program is run by the system dynamically loaded into memory for the program to call.

[Note]: Static libraries do not package resources, and if additional resources are used in the static library, they must be imported manually. (The resource is typically placed in a. bundle file)

3. Error

Undefined Symbols for Architecture i386:

"_objc_class_$_gltools", referenced from:

Objc-class-ref in VIEWCONTROLLER.O

Ld:symbol (s) not found for architecture i386

Clang:error:linker command failed with exit code 1 (use-v to see invocation)

Static Library-Error

/*

A. Build phases----Add to <StaticLibName> your targets "Target Dependencies" sections----ADD to lib<staticLibName>.a the "Link Binary with LIBR Aries "section.

B. Select "Build Settings". -----and Header Search Paths Add an entry consisting ofinclude/

C. Make sure are added to the section -all_load -ObjC Other Linker Flags .

-OBJC This flag tells the linker to load both the Objective-c class and the category defined in the library. This will make the app grow larger (because other OBJC code is loaded). However, if there are classes and categories in the static library, it is only possible to add this flag.

-all_load This flag is a bug that specializes in dealing with-OBJC. After the use of-OBJC, if the class library only category does not have the class when the category is not loaded in. The workaround is to add-all_load or-force-load. -all_load will force the linker to load the target file, even if there is no OBJC code. -force_load is available after xcode3.2. But-force_load must follow a path that only wants a static library.

*/

01. Why do Static libraries

================================================================================

1> Domestic enterprises, mastering the core technology, but also want more programmers to use its technology, so the use of "closed source" way to develop

For example: Baidu Map, Friends League, Jpush, etc.

2> in enterprise development, some of the core technology or common framework, for security and stability considerations, will also provide a static library for programmers to use

02. Features of the Static library

================================================================================

. A +. h

03. Static Library Simple Walkthrough

================================================================================

1> New Cztools Project

2> create a class method that implements a simple addition

3> compiling

# Note that when compiling a static library, you need to compile two versions of the real machine (arm) | Simulator (i386)

4> the new project will compile the generated. A +. h into the project using

04. Use of resource bundles in a static library

================================================================================

Problem: Some third-party libraries use some image material, such as the company logo.

However, because Xcode imports all footage files into Mainbundle by default at compile time, in order to avoid conflicts with programs that use static libraries.

In a static library, if you want to use a picture material, you will use the bundle's means

1> build bundles and add pictures to them

2> create a class method that returns a picture

3> compiling

4> callers need to be imported if they need to. h +. A + Xxx.bundle

05. Custom views in a static library

================================================================================

Problem: The program needs to be tested

How does a static library test?

Create a composite project

1> Review Block code pass value

06. Use of static libraries

New projects will compile the generated. A +. h drag into the project using

07. Types of static libraries

Version of the static library file (4 types)

1. Real Machine-debug version

2. Real Machine-release version

3. Simulator-debug Version

4. Simulator-release Version

Debug version VS release version

--------------------------------------------------------------------------------

-The debug version will contain complete symbolic information for easy debugging

-The debug version does not optimize the code

-The release version does not contain complete symbolic information

-The execution code of the release version is optimized

-The release version size is slightly smaller than the debug version

-The release will be faster in terms of execution speed, but does not imply a significant improvement

08. Merging of Static libraries

# Type of Detection. A

$ lipo-info LIBCZTOOLS.A

# merge. A

Lipo-create DEBUG-IPHONEOS/LIBCZTOOLS.A debug-iphonesimulator/libcztools.a-output LIBCZTOOLS.A

# Benefits of merging. A, can be debugged on the real machine during the development process, or can be debugged on the simulator

# The disadvantage of merging. A, if the static library is too large, the merge package will be very large, so many third-party static libraries. A is a version-sensitive

# Be sure to note the version in the future when using. A

It is recommended that you use the static library of the real machine when publishing.

Static Library Dynamic Library

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.