• iOS静态库的制作与引用


    iOS静态库的制作与引用

    1、Configuring Exported Headers

      To configure which headers are exported to clients, select your library project to open the project editor, select the library target to open the target editor, and select the build phases tab. If your library target has a “Copy Headers” build phase, you should delete it; copy headers build phases do not work correctly with static library targets when performing the “Archive” action in Xcode.

      Next you will add a Copy Files build phase for exporting your headers. New static library targets created with Xcode 4.4 or later will come with an appropriately-configured Copy Files phase for headers, so you should check to see if you already have one before creating one. If you do not, press “Add Build Phase” at the bottom of the target editor and choose to “Add Copy Files.” Disclose the new Copy Files build phase and set the Destination to “Products Directory". Set the Subpath to include/${PRODUCT_NAME}. This will copy files into a folder named after your library (taken from the PRODUCT_NAME build setting), inside a folder named include, inside your built products directory. The include folder inside a build products directory is in the default header search path for applications, so this is an appropriate place to put header files. Putting header files inside a folder named after your PRODUCT_NAME will allow you to segregate library headers by library name, for clarity.

      Now select the headers in your static library project which clients of that library will need to import and drag them into the new Copy Files phase. These headers will now be exported to the appropriate location inside your built products directory when you build. Any time you add new headers to your static library which clients will need to import, you should add them to this phase.

      

    2、Linking Against Your Library

      Find the “Other Linker Flags” build setting. Add the flag -ObjC to this build setting’s value if it is not already present. This flag will tell the linker to link all Objective-C classes and categories from static libraries into your application, even if the linker can’t tell that they are used. This is needed because Objective-C is a dynamic language and the linker can’t always tell which classes and categories are used by your application code.

      

    3、Importing Library Headers

      Your library’s headers are automatically included in your application’s header search path, as they are inside the built product directory’s include directory. Since your library puts its headers in a further directory named after its PRODUCT_NAME build setting, you need to include that directory in your include or import statements when importing that library’s headers. In your application’s source code you should import your library’s headers like this:

    #import "LibraryName/HeaderName.h"

    4、其它要点

      1)点添加一个.a后,该.a的路径会被自动加入到LibrarySearchPaths,如:

      

        同时LibrarySearchPaths目录下的include目录也会被作为头文件搜索路径。

  • 相关阅读:
    OI无关--关于侧边栏
    Codeforces Round #528 div1
    BZOJ 3531: [Sdoi2014]旅行
    BZOJ 4538: [Hnoi2016]网络
    Codeforces Round #527 (Div. 3)
    Avito Cool Challenge 2018
    Educational Codeforces Round 56 (Rated for Div. 2)
    Codeforces Round #526 (Div. 1)
    2018-2019 Russia Open High School Programming Contest (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
    Codeforces Round #525 (Div. 2)
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3688246.html
Copyright © 2020-2023  润新知