Writing a static library:
1. The establishment of the Static Library project:
Xcode new project, select Framework&library below iOS, with a cocoa Touch Static Library below. Direct next to create a project like print.
2. Engineering Establishment
We add a very simple "-(void) PrintA;" and "+ (void) printb;" method, the implementation of this method is very simple, the implementation in the *.M file is a "NSLog (@"); " So that the libstaticlib that we compiled can be called by other iOS projects. This piece of attention, at the moment our Print->ios Device
3. Prepare before compiling
Here is the release and debug version, need to set up a bit
4.OK, compiling
We can find our compiled LIBSTATICLIB.A this file under the products.
Note Before compilation is red: Left compilation is black: Right
5.ok
On the right side of this file, right-click Open in Finder. At this time we opened a folder with a libprint.a in it. Later we continue to write an app that calls this libprint.a. But this app will make a mistake at compile time, through this error resolution, explain some of Xcode's compilation related things. Here, we find this file based on the path under command, and use this very important command to view the LIB information!
Open Terminal writes the following command: What is this? This is where the path is.
The following are the paths on your own Mac. You need to put/users/pjk1129/library/developer/xcode/deriveddata/print-dgfkluumuexoxhcapzidtsmdgqcj/build/products/ Replace it with your path.
cd/users/pjk1129/library/developer/xcode/deriveddata/print-dgfkluumuexoxhcapzidtsmdgqcj/build/products/
We open this path manually: You can see the following information: Release-iphoneos
This is for the real machine, then we have to give the simulator and the real machine package of static library should be able to use only good. This is the following introduction!!!!!
Then open this file at the terminal: cd/users/user/library/developer/xcode/deriveddata/uitab-dbvoszbzpavyglaboxgflvrnzfce/build/ Products/debug-iphoneos
The command is: Lipo-info libprint.a, you can see the result is: Arch is Arm7. I will introduce you in detail below.
Open the terminal, use the command in the version merge, the format is
Lipo-Create "real machine version. A static library path" "emulator version. A static library path"-output "merged. A static library path"
6. Create an application that calls this LIBPRINT.A
The application is very simple, we add the *.h file just libprint.a. Then add the libprint.a that we just copied in the link Binary with library of the project's build phases.
7. After inserting H and a files
We can call this libprint.a function in control.
#import "AstroDiskAppDelegate.h"
#import "Print.h"
@implementation Astrodiskappdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Call LIBPRINT.A
[Print PRINTB];
Print *print = [[[Print alloc] init];
[Print PrintA];
Self.window = [[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];
[Self.window makekeyandvisible];
return YES;
}
8.OK, compile and run the application.
There was an error compiling. This is the key to this document. The main purpose is to introduce the compilation of static library related things.
9. You can see errors such as undefine symbols for architecture i386.
In fact, the reason for this error is very simple, because, we use the wrong compiled Libuitab.a Lib, in the simulator, we need is based on the i386 framework compiled static LIB, but this a file, we also remember the previous said ARM6 ARM7 framework. This A is actually the code that runs on the iphone, the arm architecture. In fact, the show in Finder is pointing to a library of iOS device, not a library under the I386 emulator. So how do you compile I386 's library? Did you see the Print>ios device for the second picture? We modified this iOS device to iPhone5.0 Simulator. is compiled so that you can compile the library below i386. This time our show in Finder opens a folder or a library under iOS device. We'd better take a look at that directory by ourselves. Here we use command to check the contents of the directory, as follows: You can see a Iphoneos directory and a simulator directory.
Then let's look at the difference between this directory and the one shown in 4th! There is also a libprint.a file.
10. Error cause Analysis
Release-iphoneos is based on the ARM6 ARM7 compiled library files. The Release-iphonesimulator folder below is a compiled file based on i386.
11. Merging. A files, making generic static libraries
One of these two libraries is for the simulator to run. In fact, we can use Lipo to package these two files into a generic a file. The command is as follows:
Replace the/users/user/library/developer/xcode/deriveddata/uitab-dgfkluumuexoxhcapzidtsmdgqcj/build/products with your path.
Replace the/USERS/USER/DESKTOP/LIBPRINT.A with the merged path.
lipo-create/users/pjk1129/library/developer/xcode/deriveddata/print-dgfkluumuexoxhcapzidtsmdgqcj/build/ products/release-iphonesimulator/libprint.a/users/pjk1129/library/developer/xcode/deriveddata/ print-dgfkluumuexoxhcapzidtsmdgqcj/build/products/release-iphoneos/libprint.a-output/users/pjk1129/desktop/ Libprint.a
12. After packaging the library file, we view the information
Then enter the following command: LIPO-INFO/USERS/PJK1129/DESKTOP/LIBPRINT.A
You can see the following information:
As above, as you have seen, it has the conditions of i386 and ARM7. Now that we have this static library, the supported architectures are already ARMV7 i386.
13.ok, after the above steps
After this generic library is generated, we will replace the original, call this library, in the compilation, the successful compilation, the results of the operation are as follows:
IOS Static Library Detailed