ios-Static library, dynamic library, framework analysis (II)

Source: Internet
Author: User

Create a static library of. A

The first step is to create a new project.
Generally use the name of the project name, such as I use Fmdb to create a static library, my project name is named Fmdb, created. A static library is LIBFMDB.A.


Create a new project using a static library template. png
The created project. png

The second step is to delete the "FMDB.h" and "fmdb.m" files created by the system by default, and import the source files that need to be packaged.


After you import the source file. png


Step three (mode one), modify the project configuration


Modify the configuration. png

Click "3" in the pop-up list, select "New Headers Phase", open "Headers (0 items)", click "+" in the lower left corner and select all the. h files.


Configure the. h header for files that require a burst of leaks. png

Step three (Mode II), modify the project configuration


Modify the project configuration. png

Fourth step, modify the export product configuration


Modify the compilation configuration. png

Fifth Step, modify the compilation instruction set


Set Release to No.png

Simulator: iphone4s~5:i386 iphone5s~6plus:x86_64
Real machine: Iphone3gs~4s:armv7 iphone5~5c:armv7s iphone5s~6plus:arm64
If the fifth step here, set to Yes, then the compiled. A static library contains only the instruction set of the current device.
For example: If we choose the iphone 5 simulator "Command+b" compiled, then the compiled. A static library can only run with the Iphone4s~5 simulator, with Iphone5s~6plus, will be reported to find x86_64 Libfmdb library.
Set to No, all instruction sets are packaged and merged.

Sixth step, compile (shortcut key "Command+b"

Compile, you need to compile with the emulator and the real machine, so that the LIBFMDB.A static library in the products directory will become black, right-click the show in Finder, you can enter the products directory.


Compilation result. png

Why do I need to compile the simulator and the real machine once?
You can see the "Release-iphoneos" and "Release-iphonesimulator" two files under the products directory. The former is used by real machines. A static library, which is used by the simulator. a static library.

Note: If you do not change the build configuration to release in step four, the packaged static libraries will be stored in the "Debug-iphoneos" and "Debug-iphonesimulator" two folders.
We generally use release mode, because the program is finally released after release version, so the static library is also used in release mode.

You can use terminal commands to combine the static libraries used by the emulator with the static libraries used by the real machine when you want to generalize to a static library. Command format:

Lipo-create the absolute path of the first. A file the absolute path of the second. A file-output the final. a file path.

The commands used in this article are as follows:

Lipo/users/harvey/library/developer/xcode/deriveddata/fmdb-ctegiztcjikewoeprxxtmryzetfa/build/
             /users/harvey/library/developer/xcode/deriveddata/fmdb-ctegiztcjikewoeprxxtmryzetfa/build/
-output      /users/harvey/desktop/libfmdb.a

Add :
After many practices, the third step of the operation is omitted, you can still export the normal use of the package.
If there is a category class in the static library, the "other Linker Flags" in the project configuration using the static library will need to add the parameter "-OBJC" or "-all_load".

ios-Static library, dynamic library, framework analysis (II)

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.