Header search path in XCode

I am refactoring the code I produced in XCode in order to have a certain number of static libraries that I can distribute to my partners.

I have no problem in using the static libraries as suggested in the Apple tutorial where they show how to use the static library as a subproject of the project using the library.

However, I have problems in using the produced object file (.a) and corresponding header files (.h) in a new project.

Let's say I have a library lib.a with header f1.h . What I do is create a new folder F inside the new project and copying into F the lib.a file and a folder include containing f1.h :

-- PROJECT

storyboard.storyboard     
/project
 /images.xcassets
 /Supporfing Files
 ...
 /libs
  lib.a
  /include
    /lib
      f1.h

I have these problems:

  • the headers files are found with #import f1.h and not with #import lib/f1.h

  • if I use a view controller implemented in the static library directly in a storyboard, the app fails, however if I create a new ViewController extending the one in the lib and use the latter one in the storyboard, everything works fine.

  • Using a static library in an app should not be this difficult so I am clearly doing something wrong. Do you have any workflow and settings to suggest?

    Thank you.


    When you don't have the corresponding Xcode static library projects and sources, you can use headers and a binary static archive as follows:

    Your folder structure should be like this:

    $(LIBRARIES)/release-iphoneos
        libA.a
        libF.a
        /include
            /A
                a1.h
            /F
                f1.h
    

    Your header search path for Release Configuration (or all others) should contain this path:

    $(LIBRARIES)/release-iphoneos/include

    Your library search path for iOS (not Simulator) should contain

    $(LIBRARIES)/release-iphoneos

    where libA.a and libF.a are universal binaries containing armv7, armv7s and arm64.

    You can also set a library for the Simulator: just get the binaries for Simulator (i386 or possibly a universal i386 + x86_64) and setup the library and header search paths accordingly. (Note you can set header and library search path for each configuration and architecture explicitly in the Build Settings editor).

    You can import the headers as follows:

    #import <F/f1.h>

    Otherwise

    if you have the Xcode static library projects (and the sources), simply follow the instructions in the official documentation to use and build a static library.

    链接地址: http://www.djcxy.com/p/42642.html

    上一篇: XCode中子项目的标题搜索路径

    下一篇: XCode中的标题搜索路径