C++ Xcode 找不到 #Include<> 标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2108899/
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
Xcode cannot find #Include<> header
提问by Brock Woolf
I'm trying to get Xcode to import the header file for Irrlicht.
我正在尝试让 Xcode 导入 Irrlicht 的头文件。
#include <irrlicht.h>
It says "Irrlicht.h. No such file or directory". Yes Irrlicht.h with a capital I, even though the #include is lowercase.
它说“Irrlicht.h。没有这样的文件或目录”。是的 Irrlicht.h 带有大写字母 I,即使 #include 是小写字母。
Anyway I added "/lib/irrlicht-1.6/include" in the header search paths for the Xcode project, yet it still doesn't find it.
无论如何,我在 Xcode 项目的标题搜索路径中添加了“/lib/irrlicht-1.6/include”,但它仍然没有找到它。
The only thing I've tried that does work is:
我尝试过的唯一有效的方法是:
#include "/lib/irrlicht-1.6/include/irrlicht.h"
This is a bit ridiculous though, #include should work, I don't understand why it isn't working.
不过这有点荒谬,#include 应该可以工作,我不明白为什么它不工作。
Update (here are more details on the error):
更新(这里有关于错误的更多细节):
/lib/PAL/pal_benchmark/palBenchmark/main.h:31:0
/lib/PAL/pal_benchmark/palBenchmark/main.h:31:22: error: irrlicht.h: No such file or directory
回答by Brock Woolf
I figured this out. Perhaps someone can comment as to why this is the case.
我想通了。也许有人可以评论为什么会这样。
The Header was located in this directory:
标题位于此目录中:
/lib/irrlicht-1.6/include/
If I added that path to: "Header Search Paths" Xcode still wouldn't find the path when I built the project.
如果我将该路径添加到:“Header Search Paths”,Xcode 在我构建项目时仍然找不到路径。
Solution:Add the header path to: "User Header Search Paths"instead.
解决方案:将标题路径添加到:“用户标题搜索路径”。
It boggles me why I had to do this, as I frequently add my header paths to "Header Search Paths" and then #includes just work. Hopefully this can help someone else who gets this same issue.
我很困惑为什么我必须这样做,因为我经常将我的标题路径添加到“标题搜索路径”,然后 #includes 就可以工作了。希望这可以帮助遇到同样问题的其他人。
回答by diciu
Both
两个都
#include <irrlicht.h>
#include "irrlicht.h"
should work as long as the "-I" argument to gcc includes the path of the directory enclosing the header file. If irrlicht.his part of /usr/include the "-I" option is no longer required.
只要 gcc 的“-I”参数包含包含头文件的目录路径,就应该可以工作。如果irrlicht.h是 /usr/include 的一部分,则不再需要“-I”选项。
回答by Paul R
Rather than explicitly adding include paths to your project settings, an easier and more convenient solution for this kind of situation is to just drag the directory containing your .h files (/lib/irrlicht-1.6/include in this case) into the project files pane. This adds the headers to your project of course, and makes it easy to browse them and search for symbols, etc, and it also adds the directory path to gcc compiles, so that you don't have to manage include paths explicitly.
对于这种情况,一个更简单、更方便的解决方案是将包含 .h 文件的目录(在本例中为 /lib/irrlicht-1.6/include)拖到项目文件中,而不是明确地向项目设置添加包含路径窗格。这当然会将标题添加到您的项目中,并且可以轻松浏览它们并搜索符号等,并且它还会将目录路径添加到 gcc 编译中,因此您不必显式管理包含路径。
回答by horseshoe7
and furthermore, a flat file hierarchy isn't what you want. Dragging files into Xcode flattens your hierarchy. What about for example when you want to have multiple Targets, with a "TargetName/settings.h" file for that target. you'll have many settings.h files that you need to keep unique via its folder name.
此外,平面文件层次结构不是您想要的。将文件拖到 Xcode 中会使您的层次结构变平。例如,当您想拥有多个目标时,该目标的“TargetName/settings.h”文件如何。您将有许多 settings.h 文件,您需要通过其文件夹名称保持唯一性。
回答by AudioGL
I understand that this is an old post, but it does rank quite high on Google, so I thought I would add some information
我知道这是一篇旧帖子,但它在 Google 上的排名确实很高,所以我想我会添加一些信息
Under XCode 3.2.6, I had an issue where XCode could not find a header file. It turns out that one of the filepaths included a space in it, and XCode interpreted it improperly.
在 XCode 3.2.6 下,我遇到了 XCode 找不到头文件的问题。事实证明,其中一个文件路径中包含一个空格,并且 XCode 对其进行了不正确的解释。
For example: With a path like "Users/Username/Desktop/Project/Some Headers"
例如:使用类似“用户/用户名/桌面/项目/某些标题”的路径
Here was the excerpt from the GCC Commandline: "-I/Users/Username/Desktop/Project/Some" "-I/Headers"
以下是 GCC 命令行的摘录:“-I/Users/Username/Desktop/Project/Some”“-I/Headers”
To see your build log provided by XCode, there is a good tutorial here: How do you show Xcode's build log? (Trying to verify if iPhone distribution build zip was created correctly.)
要查看 XCode 提供的构建日志,这里有一个很好的教程:如何显示 Xcode 的构建日志?(尝试验证是否正确创建了 iPhone 发行版构建 zip。)