xcode 为什么找不到静态库头文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1095452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:39:34  来源:igfitidea点击:

Why are static library headers not found?

iphonexcodegccstatic-librariesxcodebuild

提问by Felixyz

I've used Clint Harris' tutorialto set up code sharing between projects, and everything works just as expected on my computer. But on my co-worker's machine, it seems the compiler doesn't find the header file from the static library project when he builds.

我使用Clint Harris 的教程设置了项目之间的代码共享,一切都在我的计算机上按预期工作。但是在我同事的机器上,编译器在构建时似乎没有从静态库项目中找到头文件。

My co-worker got my project by cloning a git repository. We've gone through all relevant build flags and XCode settings n times, but the project simply refuses to compile on his machine.

我的同事通过克隆 git 存储库获得了我的项目。我们已经检查了所有相关的构建标志和 XCode 设置 n 次,但该项目只是拒绝在他的机器上编译。

This is what I asked my co-worker to do, mostly copied and pasted from the tutorial:

这是我让我的同事做的,主要是从教程中复制粘贴的:

  1. Make sure there is NO blank space in the complete path to the projects' directory.
  2. Inside the projects directory, create another folder called "build_output".
  3. In XCode, under “XCode > Preferences" choose the "Building” tab and set “Place Build Projects in” to “Customized location” and specify the path to the common build directory you created.
  4. Set “Place Intermediate Build Files in” to “With build products.”
  5. Choose the “Source Trees” tab and create a new Source Tree variable by clicking on the “+” button and filling in the columns. In both "Setting Name" and "Display Name", put [the name of the shared project which created the static library]. In path, you put the full path to the framework folder.
  1. 确保项目目录的完整路径中没有空格。
  2. 在项目目录中,创建另一个名为“build_output”的文件夹。
  3. 在 XCode 中,在“XCode > Preferences”下选择“Building”选项卡并将“Place Build Projects in”设置为“Customized location”并指定您创建的公共构建目录的路径。
  4. 将“Place Intermediate Build Files in”设置为“With build products”。
  5. 选择“Source Trees”选项卡并通过单击“+”按钮并填写列来创建一个新的 Source Tree 变量。在“设置名称”和“显示名称”中,输入[创建静态库的共享项目的名称]。在路径中,您放置了框架文件夹的完整路径。

Following these steps, the project that uses the static library should compile the same on his machine as on mine. But it doesn't. Basically, the error he gets is:

按照这些步骤,使用静态库的项目应该在他的机器上和我的机器上编译相同。但事实并非如此。基本上,他得到的错误是:

error: TheFrameworkHeader.h: No such file or directory

and then a string of other errors caused by the missing header.

然后是由丢失的标头引起的一串其他错误。

Any strategies for trouble-shooting this? Or anyone who had a similar experience and could share some hard-earned knowledge? Is anything missing from the instructions I've summarized? Do I need to set the roles of headers in the Copy Headers build phase when compiling a static library?

任何解决此问题的策略?或者任何有类似经历并且可以分享一些来之不易的知识的人?我总结的说明中是否缺少任何内容?编译静态库时是否需要在Copy Headers构建阶段设置headers的角色?

回答by Felixyz

Despite some helpful advice, I never figured this one out, but here's a little info for anyone in a similar situation. I created the library and dependent project by splitting an original project into two. At first, the library and application were just two targets within the same project. Later, I moved the app to a separate project. Everything seemed to work, and I pushed both projects to remote git repositories. When these were cloned on other computers, however, the library headers were not found.

尽管有一些有用的建议,但我从来没有想过这个,但这里有一些信息,供处于类似情况的人使用。我通过将原始项目一分为二来创建库和依赖项目。起初,库和应用程序只是同一个项目中的两个目标。后来,我将该应用程序移至一个单独的项目。似乎一切正常,我将两个项目都推送到远程 git 存储库。但是,当在其他计算机上克隆这些文件时,找不到库头文件。

Later, I discover that the same error occurred when I cloned the projects on the original computer. After a lot of struggle, I pinned it down to one scary detail: the name of the dependent project's folder!(That is, the project with the application, not the library.) Not the name of the .xcodeproject package, not the application identifier, but the name of the containing folder. As soon as I change that, everything works. If I change it back to the original name (on any computer), again the headers are not found.

后来发现在原电脑上克隆项目时也出现同样的错误。经过一番挣扎,我把它归结为一个可怕的细节:依赖项目文件夹的名称!(也就是说,包含应用程序的项目,而不是库。)不是 .xcodeproject 包的名称,不是应用程序标识符,而是包含文件夹的名称。一旦我改变它,一切正常。如果我将其改回原始名称(在任何计算机上),则再次找不到标题。

If anyone has any insight on this, please post an answer!

如果有人对此有任何见解,请发布答案!

EDIT: Since I posted this, the same problem occured with another project, and again, merely renaming the folder that contains the .xcodeproject folder fixed the problem.

编辑:自从我发布了这个,同样的问题发生在另一个项目中,同样,仅仅重命名包含 .xcodeproject 文件夹的文件夹就解决了这个问题。

回答by mvd

I don't think it is Git, I think it's xcode. I got a very similar problem here, where xcode / xcodebuild resolves an include path falsely (making it a simple .) With the exactly the same library project and xcconfig files (clean checkout from svn repo) but another containing folder - it works. So, thanx for the solution and don't blame Git anymore ;-)

我不认为它是 Git,我认为它是 xcode。我在这里遇到了一个非常相似的问题,其中 xcode / xcodebuild 错误地解析了一个包含路径(使其变得简单。)使用完全相同的库项目和 xcconfig 文件(从 svn repo 干净签出)但另一个包含文件夹 - 它有效。所以,谢谢你的解决方案,不要再责怪 Git 了 ;-)

回答by Max Lybbert

If you're having trouble building on a particular machine, then the problem likely is a machine or user setting. Such as an environment variable(perhaps INCLUDE_PATH or one of its relatives -- XCode uses GCC). You may have a "." in one of these variables.

如果您在特定机器上构建时遇到问题,那么问题可能出在机器或用户设置上。例如环境变量(可能是 INCLUDE_PATH 或其亲属之一——XCode 使用 GCC)。你可能有一个“。” 在这些变量之一。

The best way to fix this would be to add the needed folder path to the -I switch in the build script.

解决此问题的最佳方法是将所需的文件夹路径添加到构建脚本中的 -I 开关。

回答by Max Lybbert

I often forget to check this: are you sure that the missing file (i.e., TheFrameWorkHeader.h" is in the git repository? It may well be that your build settings are correct, but the file somehow did not get added to git correctly.

我经常忘记检查这个:你确定丢失的文件(即 TheFrameWorkHeader.h”在 git 存储库中吗?很可能你的构建设置是正确的,但文件不知何故没有正确添加到 git 中。

回答by dstnbrkr

Double check that the "Search Paths->User Header Search Paths" build setting (for all configurations) points to the directory containing the shared Xcode project (you can use the new Source Tree variable you created).

仔细检查“Search Paths->User Header Search Paths”构建设置(对于所有配置)是否指向包含共享 Xcode 项目的目录(您可以使用您创建的新 Source Tree 变量)。