Xcode 4 make static library graphics and text detailed _ios

Source: Internet
Author: User

Recently in Apple's iOS development, there is a need to develop a static library, itself to develop iOS, allowing only static libraries or frameworks. It was not found on the Xcode that allowed compilation, as in the case of *.so on Android and DLLs on Win32. However, frameworks such as the framework, estimates are similar to the implementation of dynamic libraries, but not specifically studied, follow-up in-depth study.

The development of my static library for this document is based on Xcode4.2 and iOS SDK5.0. Xcode4 with the previous Xcode3 still have a lot of difference.

Here is a simple example of a static library and a call to a static library.

The writing of static libraries:

1. The establishment of the Static Library project:

Xcode New Project, select the framework&library below iOS, and here's a cocoa touch Static Library. Direct next to build a project such as print.


2. Project Establishment

We add very simple "-(void) PrintA;" and "+ (void) printb;" method, the implementation of this method is also very simple, in the *.m file implementation is a "NSLog (@"); So our compiled libstaticlib can be invoked by other iOS projects. This piece of attention, at present our Print->ios Device



3. Prepare before compiling

Here is the release and debug version, you need to set up


4.OK, compiling

We can find our compiled LIBSTATICLIB.A this file below the products.

Note the red before compilation: left-compiled black: Right


5.ok

On the right this file right-click the open in Finder. At this time we opened a folder, there is a libprint.a. Later we continue to write an app that calls this libprint.a. But this app is going to go wrong at compile time, and by this error, it explains some of Xcode's compilation-related things. Here, we find this file according to the path under command, and look at this information with this very important command!

Open the terminal and write the following command: What is this? This is where the path is

The following are the paths on your own Mac. You need to/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 manually open this path: 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 the static library should be able to use the good. Here's a description of!!!!!.


And then open the 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 of the display is: Arch is Arm7. I'll give you a specific introduction.


6. Create an application that calls this LIBPRINT.A

The application is very simple, we add just libprint.a *.h file. Then add the libprint.a that we just copied out of the link Binary with library in this project's build phases.



7. After inserting the H and a files

We can call this libprint.a function in control.

#import "AstroDiskAppDelegate.h"

#import "Print.h"


@implementation Astrodiskappdelegate


@synthesize window = _window;


-(void) dealloc

{

[_window release];

[_viewcontroller release];

[Super Dealloc];

}


-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

{

Call LIBPRINT.A

[Print PRINTB];

Print *print = [[[Print alloc] init] autorelease];

[Print PrintA];


Self.window = [[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]] autorelease];

[Self.window makekeyandvisible];

return YES;

}



8.OK, compile and run this application.

There was an error compiling. This is the key to this document. is mainly 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 compiler libuitab.a Lib, in the simulator, we need is based on the i386 framework compiled static LIB, but this a file, we still remember the previous ARM6 ARM7 framework. This is actually the code that runs on the arm architecture of the iphone. In fact, the show in finder points to a library of iOS device, not a library under the i386 simulator. So how do you compile I386 's library? See the second picture of Print>ios device? We modified this iOS device to iPhone5.0 Simulator. is compiled so that you can compile the library below the i386. This time we show the In Finder Open folder or the library under iOS device. We'd better take a look at the catalogue ourselves. Here we use the command to look at the table of contents, as follows: You can see a Iphoneos directory and a simulator directory.


Then we'll look at how this directory differs from the directory shown in article 4th! There is also a libprint.a file.



10. Error cause Analysis

Release-iphoneos inside is based on the ARM6 ARM7 compiled library files. The Release-iphonesimulator folder is based on i386 compiled files.

11. Merge. A file, make general static library

One of these two libraries is for the real machine to run one is for the emulator to run. In fact, we can use Lipo to package these two files into a generic a file. The order 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 packing 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 you can see, it has the conditions of i386 and ARM7. Now we have this static library, supported by the architecture is ARMV7 i386.


13.ok, after the above steps

After this common library is generated, we will originally, call this library for replacement, in the compilation, the successful compilation, the results of the operation are as follows:

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.