Static libraries on iOS and static libraries on iOS

Source: Internet
Author: User

Static libraries on iOS and static libraries on iOS

Recently, the real machine debugging of the project was conducted, and a pitfall was discovered. The following describes how to use static libraries on iOS:

First, we directly use a project that can be run to create a static library. Most of the websites first create a static library and then write the content. Let's look at my methods.

1. Import the sub-project to the project, delete the running file of the sub-project, and create a static library !!! (Do not create the framework. For a long time, let's talk about it.) create a. a static library. The name does not affect your liking. I generally use the original name.

2. Then, add the Link Build Phases-> Target Dependencies and Link Binary With Libraries to the static library we created.

3. we also need to select Sub-Projects for some configuration in the sub-project, then select your own static library Build Phases-> Compile Sources in TARGETS to add the implementation files you need (. m Files) if there are a lot of files, there is actually a lazy way to create a static library and drag these files from the original project. Xcode will automatically add these Implementation files. (I used to add more than 100 files by myself .)

4. This leaves the last step. In the main project, set the file location in TARGETS-> Build Settings-> User Header Search Paths. Is the folder location example: ../PKQ ../is the meaning of the upper-level directory. In this option, recursive is used to traverse the entire file (sometimes it is not easy to use ..)

5. In this way, we can call our static library elsewhere. 0v0

 

 

The following are some notes:

1. The static library cannot contain libsqlite3.tbd files. Directly add the bundle file to the main project.

2. if there is a classification in the static library, xcode cannot normally load these files. Find the Target of the main project and choose Build Setting> Linking to change its Other Linker Flags to-all_load or-force_load. -All_load means to load all the projects. Generally, this can be added, but it will affect the running speed first, and sometimes other files may report an error for some reason. I have encountered this problem in my previous project. The previous project was compiled in C ++ and then used-all_load to produce many errors. -Force_load is required in this case, $ (SRCROOT )/.. /Vendors/build/Debug-iphonesimulator/libVendors. path a directly pulls the static library and deletes it. Then, it just has a space with-force_load.

Next, we should mention that the default dynamic library created by framework xcode mentioned above cannot be installed on a real machine, but you can change it to a static library. Set Target-> Mach-O Type to Static Library, and then change to Static Library. However, this static library is. framework and cannot use the-force_load label !!! (I finally deleted this static library that created. a and pulled the implementation file again =)

3. I don't know what else to pay attention. The static library is merged, because it is very troublesome to change the path. Then we will combine the real machine and simulator into a. a file. In this case, we need to complete the cd in the terminal and then there are two operations in the target path. the static library file of lipo-info knows the Mode Supported by the static library. This is a rough look, but it is basically useless. Lipo-create Debug-iphoneos/libVendors. a Debug-iphonesimulator/libVendors. a-output libVendors. a refers to the command to synthesize two static libraries into a static library. After merging, drag the new static library to the original path to overwrite it.

If you have any questions, please tell me that I am also a newbie. Hope to help you

 

 

 

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.