Xcode链接的项目头文件未找到

时间:2021-05-05 22:49:31

Here is the situation I have:
ProjectA - Xcode static library project.
ProjectA contains logical code group ExternLib with file ExternLib.h. ExternLib.h itself is in the folder Classes/lib/ExternLib (relative to ProjectA folder). Within ProjectA, I use ExternLib.h simply as: #import "ExternLib.h". This works fine.

这是我的情况:ProjectA - Xcode静态库项目。 ProjectA包含带有文件ExternLib.h的逻辑代码组ExternLib。 ExternLib.h本身位于文件夹Classes / lib / ExternLib(相对于ProjectA文件夹)中。在ProjectA中,我将ExternLib.h简单地用作:#import“ExternLib.h”。这很好用。

Next I have ProjectB. This includes ProjectA as a linked Xcode project. The target has been added correctly etc. However, when I include a file in ProjectB which in turn includes ExternLib.h, upon building ProjectB, I get an error saying that the file ExternLib.h cannot be found.

接下来我有ProjectB。这包括ProjectA作为链接的Xcode项目。目标已正确添加等。但是,当我在ProjectB中包含一个文件,而该文件又包含ExternLib.h时,在构建ProjectB时,我收到一条错误消息,指出无法找到文件ExternLib.h。

I have tried adding the path to ExternLib.h to the header search path (all types: relative, absolute, with recursion etc.) but to no avail. I have checked that static library target has the copy headers step and the file ExternLib.h is included in it.

我已经尝试将ExternLib.h的路径添加到头搜索路径(所有类型:相对,绝对,递归等),但无济于事。我已检查过静态库目标是否具有复制头部步骤,并且文件ExternLib.h包含在其中。

Anybody able to shed some light on how to get around this?

有人能说清楚如何解决这个问题吗?

2 个解决方案

#1


1  

  1. Add a Run Script Build Phase to the target for ExternLib that executes

    将Run Script Build Phase添加到执行的ExternLib的目标

    mkdir -p "${BUILT_PRODUCTS_DIR}ExternLibHeaders"
    
  2. Add a Copy Files build phase that copies the ExternLib header files into ${BUILT_PRODUCTS_DIR}ExternLibHeaders, and add all of ExternLib's headers into that phase.

    添加一个复制文件构建阶段,将ExternLib头文件复制到$ {BUILT_PRODUCTS_DIR} ExternLibHeaders中,并将所有ExternLib的头添加到该阶段。

  3. In the app target for ProjectB, add ${BUILT_PRODUCTS_DIR}/ExternLibHeaders/ to the Header Search Paths for all configurations.

    在ProjectB的应用目标中,将$ {BUILT_PRODUCTS_DIR} / ExternLibHeaders /添加到所有配置的标头搜索路径。

  4. In Xcode > Preferences > Build, set the Build Products Directory to some common location.

    在Xcode> Preferences> Build中,将Build Products Directory设置为某个公共位置。

The fourth step is crucial; it ensures that BUILT_PRODUCTS_DIR is the same for both projects.

第四步至关重要;它确保两个项目的BUILT_PRODUCTS_DIR相同。

#2


0  

It's really hard to say what might have gone wrong.

很难说出现了什么可能出错。

I'd start from scratch with a tutorial on building and using static libraries, and see if any of the steps jog any ideas out of you.

我将从头开始,提供有关构建和使用静态库的教程,并查看是否有任何步骤让您想出任何想法。

#1


1  

  1. Add a Run Script Build Phase to the target for ExternLib that executes

    将Run Script Build Phase添加到执行的ExternLib的目标

    mkdir -p "${BUILT_PRODUCTS_DIR}ExternLibHeaders"
    
  2. Add a Copy Files build phase that copies the ExternLib header files into ${BUILT_PRODUCTS_DIR}ExternLibHeaders, and add all of ExternLib's headers into that phase.

    添加一个复制文件构建阶段,将ExternLib头文件复制到$ {BUILT_PRODUCTS_DIR} ExternLibHeaders中,并将所有ExternLib的头添加到该阶段。

  3. In the app target for ProjectB, add ${BUILT_PRODUCTS_DIR}/ExternLibHeaders/ to the Header Search Paths for all configurations.

    在ProjectB的应用目标中,将$ {BUILT_PRODUCTS_DIR} / ExternLibHeaders /添加到所有配置的标头搜索路径。

  4. In Xcode > Preferences > Build, set the Build Products Directory to some common location.

    在Xcode> Preferences> Build中,将Build Products Directory设置为某个公共位置。

The fourth step is crucial; it ensures that BUILT_PRODUCTS_DIR is the same for both projects.

第四步至关重要;它确保两个项目的BUILT_PRODUCTS_DIR相同。

#2


0  

It's really hard to say what might have gone wrong.

很难说出现了什么可能出错。

I'd start from scratch with a tutorial on building and using static libraries, and see if any of the steps jog any ideas out of you.

我将从头开始,提供有关构建和使用静态库的教程,并查看是否有任何步骤让您想出任何想法。