ios development static library generation

First of all, let's briefly talk about it: A library is a collection of program code and a way to share code.

 

 Divided into open source libraries (sd, mi, afn) and closed source libraries (no specific implementation can be seen)

 

 

Closed source library is divided into static library and dynamic library

Static Libraries: .a and .framework

Dynamic Libraries: .dylib and .framework

 

The difference between static library and dynamic library

Static library: When linking, the static library will be completely copied into the executable file, and if it is used multiple times, there will be multiple redundant copies 

Dynamic library: It is not copied when linking, the program is dynamically loaded into the memory by the system when it is running, for the program to call, the system only loads it once, and it is shared by multiple programs, saving memory 

Note: You cannot upload the appstore using your own dynamic library

Next, let's talk about the method of making .a

Step 1: Create a new project and choose as follows:

 

The next step is to create a new project.

After opening the project, kill the claimed .h and .m files as follows

 

Part 2: Drag the class that needs to be encapsulated into the project

Then select the .h file that needs to be exposed, and the .m file will be automatically compiled into the .a file

 

Select the real device, then Command+B to compile, the libMJRefresh.a file changes from red to black

That's it, show in finder is the required library.

It should be noted here: Select the real machine to run the .a file required for the real machine to run, which can only be run on the real machine, and an error will be reported when running the simulator.

Because of the difference between the cpu architecture of the mobile phone and the computer. .

Solution:

Merge the .a from the real machine command + B and the .a from the simulator command + B

The trick of merging static libraries to make both simulators and real machines work

lipo -create /Users/gti/Desktop/Debug-iphoneos/libJTK.a /Users/gti/Desktop/Debug-iphonesimulator/libJTK.a -output /Users/gti/Desktop/libJTK.a

lipo -create : fixed command   

/Users/gti/Desktop/Debug-iphoneos/libJTK.a The location of the .a file from the real machine

/Users/gti/Desktop/Debug-iphonesimulator/libJTK.a The location of the .a file from the simulator 

output fixed command line

/Users/gti/Desktop/libJTK.a The location and name of the final file that merged ok

 

 

use .a

How to use .a

Just drag and drop .a , .h , resource files to other projects

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324697032&siteId=291194637