简体   繁体   English

Xcode找不到#Include <>标头

[英]Xcode cannot find #Include<> header

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". 它说“Irrlicht.h。没有这样的文件或目录”。 Yes Irrlicht.h with a capital I, even though the #include is lowercase. 是的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

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. 令我难以理解为什么我必须这样做,因为我经常将我的标题路径添加到“标题搜索路径”,然后#includes只是工作。 Hopefully this can help someone else who gets this same issue. 希望这可以帮助那些得到同样问题的其他人。

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. 只要gcc的“-I”参数包含封闭头文件的目录的路径,它就应该工作。 If irrlicht.h is part of /usr/include the "-I" option is no longer required. 如果irrlicht.h是/ usr / include的一部分,则不再需要“-I”选项。

I understand that this is an old post, but it does rank quite high on Google, so I thought I would add some information 我知道这是一个老帖子,但它确实在谷歌上排名很高,所以我想我会添加一些信息

Under XCode 3.2.6, I had an issue where XCode could not find a header file. 在XCode 3.2.6下,我遇到了XCode无法找到头文件的问题。 It turns out that one of the filepaths included a space in it, and XCode interpreted it improperly. 事实证明,其中一个文件路径包含一个空格,而XCode对它进行了不正确的解释。

For example: With a path like "Users/Username/Desktop/Project/Some Headers" 例如:使用类似“Users / Username / Desktop / Project / Some Headers”的路径

Here was the excerpt from the GCC Commandline: "-I/Users/Username/Desktop/Project/Some" "-I/Headers" 以下是GCC Commandline的摘录:“ - 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? 要查看XCode提供的构建日志,这里有一个很好的教程: 如何显示Xcode的构建日志? (Trying to verify if iPhone distribution build zip was created correctly.) (尝试验证是否正确创建了iPhone分发构建zip。)

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. 对于这种情况,更简单,更方便的解决方案是将包含.h文件的目录(在本例中为/lib/irrlicht-1.6/include)拖放到项目文件中,而不是明确地将include路径添加到项目设置中。窗格。 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. 这当然会将标题添加到项目中,并且可以轻松浏览它们并搜索符号等,还可以将目录路径添加到gcc编译中,这样您就不必显式管理包含路径。

and furthermore, a flat file hierarchy isn't what you want. 此外,平面文件层次结构不是您想要的。 Dragging files into Xcode flattens your hierarchy. 将文件拖入Xcode会使您的层次结构变得扁平化。 What about for example when you want to have multiple Targets, with a "TargetName/settings.h" file for that target. 例如,当您想要具有多个目标时,该目标具有“TargetName / settings.h”文件。 you'll have many settings.h files that you need to keep unique via its folder name. 您将拥有许多您需要通过其文件夹名称保持唯一的settings.h文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM