Static and dynamic repositories:
- Static library: complete copy to executable file when linking, multiple use of multiple redundant copies.
- Dynamic library: link does not copy, program run by the system dynamically loaded into memory, for program call, the system only loaded once, multiple programs shared, saving memory.
What is the difference between.a and. Framework
- A is a pure binary file. The. Framework has resource files in addition to binary files.
- A files cannot be used directly, but at least. H files must be used together. Framework files can be used directly.
.a + .h + sourceThe File = framework.Copy the code
A static library production
We create debug projects directly, not static libraries. Because of the need for breaking points, wait until debugging is successful before packaging the corresponding static library.
1. Create a common project
Create the project and add the Static Library to the project, as shown below.
2. Set the visible. H file.
Build Phases –> Copy Files.
3. Modify the supported architecture
Build Settings –> Build Active Architecture Only –> Debug to support all mobile Architecture.
4. Then compile
Select PrintTarget, then select Generic iOS Device and each emulator to compile. After compiling, we can see that libPrint. A in the Products folder in the project changes from red to black, and then show in Finder. Take a look at the generated file.
5. Merge the static libraries of the simulator and the real machine
- You can use
Lipo-info + static library name
Command to view the frameworks supported by the static library. - If you want the simulator and the real machine to share a static library, you can use terminal commands to do so. 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
.
Framework static library production
1. Create a common project
2. Change whether the packaged framework is a dynamic library or a static library
Framework projects default to dynamic libraries. Static Library configuration: Build Settings –> Mach-O Type –> change to Static Library. Build Settings –> Build Active Architecture Only –> Debug to support all mobile Architecture.
3. Write code to set the visible header file
After writing the code,Build Phases –> Headers –> public adds the header file.
4. Then compile
Select LibTestTarget, then select Generic iOS Device and any emulator to compile. After compiling, you will see that libtest. framework in the Products folder changes from red to black. Then show in Finder to see the generated file.
5. Merge the static libraries of the simulator and the real machine
- You can use
The name of a binary file in the lipo-info framework
Command to view the frameworks supported by the static library. - If you want the simulator and the real machine to share a static library, you can use terminal commands to do so. The merge command is:
Lipo-create Absolute path to the binary file in the first framework absolute path to the binary file in the second framework -output Final binary file path
.
6. Pay attention to
Note: If the static library has the category class, the Other Linker Flags parameter -objc or -all_LOAD needs to be added to the project configuration using the static library.
Full Demo address
Making: github.com/CaoXueLiang…