如何包括一个静态库并且它的#import路径仍然有效? [英] How to include a static library and have its #import paths still be valid?

查看:181
本文介绍了如何包括一个静态库并且它的#import路径仍然有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个使用以下文件结构创建的静态库:

Say I have a static library that was created with the following file structure:


  • Folder1

    • File1.h


    • File2.h

    现在位于 File1.h ,它指的是没有路径的 File2.h (例如 #import File2.h )。库成功构建。 (它不需要完整路径(即 #import Folder2 / File2.h ),因为这两个文件都是同一个项目的一部分。)

    Now inside of File1.h, it refers to File2.h without a path (e.g. #import File2.h). The library builds successfully. (It doesn't require the full path (i.e. #import Folder2/File2.h) because both files are part of the same project.)

    现在,当我将这个库包含在另一个项目中时, #import File2.h 语句不再编译,我必须将其更改为 #import Folder2 / File2.h (或类似的东西)。这意味着我必须修改原来的库,这是不好的。

    Now when I include this library in another project, that #import File2.h statement no longer compiles, and I have to change it to #import Folder2/File2.h (or something similar). This means that I have to modify the original library, which is not good.

    我得到的具体错误消息是:

    The specific error message I get is:


    File2.h:没有此类文件或目录

    File2.h: No such file or directory

    一个方法让它知道这两个文件应该是这个新项目的一部分,因为我看到的只有两个文件,我包括了 MyLib.xcodeproj lixMyLib.a

    There doesn't seem to be a way to let it know that both files should be a part of this new project, since the only two files I see after I included the library are MyLib.xcodeproj and lixMyLib.a.

    我在我的新项目中添加静态库的方法是通过执行以下操作:

    The way I included the static library in my new project is by doing the following:


    1. MyLib.xcodeproj 拖入我的新专案。

    2. libMyLib.a 文件添加到我的新项目目标。

    3. 添加到标题搜索路径目录(包含 Folder1 Folder2 的文件夹)。

    1. Drag MyLib.xcodeproj into my new project.
    2. Add the libMyLib.a file to my new project's target.
    3. Add to the Header Search Paths a relative path to the home directory of my library (the folder that contains Folder1 and Folder2).


      有没有什么办法,我可以让它自动知道在哪里找到这些文件,因为它是在图书馆本身做的?我意识到我可以添加路径 Folder1 Folder2 到我的新项目的标题搜索路径,但我'寻找一个更好的方式,因为这两个文件夹只是一个例子,它可以很容易地50个文件夹,我需要包括。我正在寻找一个解决方案,如果可能,不需要我输入所有50个文件夹的路径。

    Is there any way I can have it automatically know where to find these files just as it was able to do in the library itself? I realize that I can probably add the paths Folder1 and Folder2 to the Header Search Paths of my new project, but I'm looking for a better way, since these two folders are just an example, and it could just as easily be 50 folders I would need to include. I'm looking for a solution which doesn't require me to type the paths to all 50 of those folders, if possible.

    推荐答案

    p>尝试检查所有这些标头的父文件夹路径旁边的递归复选框。

    Try checking the "Recursive" checkbox next to the path to the parent folder of all those headers.

    这篇关于如何包括一个静态库并且它的#import路径仍然有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆