IOS static Library Creation and usage Problems

Source: Internet
Author: User

IOS static Library Creation and usage Problems
 
Static library usage goals: (.)
> Create a static database by yourself (available) (the first three steps)
> Create a Simulator version and a real machine version (step 4)
> Merge two versions (Step 6)


To create a static database:
1. Select the file type to be created: Cocoa Touch Static Library (. a file)


2. Import the files to be encapsulated
Select the project and find target (static library)-> Build Phases-> Compile Sources to add the class to be encapsulated


3. Set the compilation Configuration
Compile EditSchem-> Select Run, select info, and set its Build Configuration: release/debug
Select Project: Project-> Build Setting-> Code Signing Identity, and select the corresponding, release or debug, set it to iOS Developer [Note that the selected Project is not Targets]


4. select project-> iOS Device, and click "run" to generate the arm6 and arm7 static libraries. [Note: the static libraries generated at this time are applicable to real machines, not suitable for simulators] If you need to generate a static library of i386 [For simulators], you can select a simulator to run it again. [do not open it with showInFinder, otherwise, you can find the static library file in Build> Products Debug-iphonesimulator of the corresponding project in the corresponding DerivedData.


Tip: You can run the "lipo-inof path/file name. a" command to check whether the file meets the conditions of "arm" or "i386 ".


5. After compilation is successful, you can use

Note: The difference between the Debug version and the release version lies in the use of the dynamic library. It is a static library file with the corresponding simulator and real machine mode.


Possible problems: undefine symbols for architecture i386
Problem Analysis: compiled by mistake. a lib: in the simulator, we need static lib compiled based on the i386 architecture. However, this a file is actually compiled by the arm6 arm6 arm7 architecture. Because we use show in finder to point to an ios device library, not the library in the i386 simulator. If you want to compile the i386 library, pay attention to the 4th operations, go to DerivedData and find static lib in iphonessimulator.
In fact, when we open the Products Debug file, we can see that there are two folders:
Release-iphoneos or Debug-iphoneos: Contains library files compiled based on arm6.
Release-iphonesimulator: Contains i386-based files.




6. Merge the versions supported by the simulator with those supported by the real machine.
Lipo-create path/Simulator version. a path/real machine version. a-output path/static library name.


After packaging, you can view the supported versions:
Lipo-info path/merged static library name.


Result Display:
Li *****: Desktop mac $ lipo-info libdemo.

Ubuntures in the fat file: libdemo. a are: armv7 i386 arm64

 


 

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.