C语言 如何在xcode项目中设置包含路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14134064/
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
How to set include path in xcode project
提问by RyanM
I am trying to use a C library in an Objective-C Xcode project.
我正在尝试在 Objective-C Xcode 项目中使用 C 库。
The libraries directory structure is as follows:
库目录结构如下:
-- include/
|-- config.h
|-- lib/
| |-- file1.h
| |-- file2.h
| |-- file3.h
The library's docs say to include file1.h, and file1.h includes file2.h and file3.h.
该库的文档说包含 file1.h,而 file1.h 包含 file2.h 和 file3.h。
I am getting "file not found" errors for the includes of file2.h and file3.h`. They are included by file1.h in the following manner:
我收到包含 file2.h 和 file3.h` 的“找不到文件”错误。它们以下列方式包含在 file1.h 中:
#include <lib/file1.h>
#include <lib/file2.h>
I read herethat these angle-brackets instruct the preprocessor to search for include files along the path specified by the INCLUDE environment variable, as opposed to searching in the same directory as the file that contains the #include.
我在这里读到,这些尖括号指示预处理器沿着 INCLUDE 环境变量指定的路径搜索包含文件,而不是在与包含 #include 的文件相同的目录中搜索。
So I added the INCLUDE environment variable in Xcode by going to Product->Edit Scheme.. and set it to /the-whole-path-to/include/however, I am still getting the file not found errors.
因此,我通过转到 Product->Edit Scheme 在 Xcode 中添加了 INCLUDE 环境变量,并将其设置为/the-whole-path-to/include/但是,我仍然收到未找到文件的错误。
The files are successfully included if I change file1.h to include them like this:
如果我将 file1.h 更改为包含这些文件,则成功包含这些文件:
#include "file2.h"
but I'd rather not do that for every file in the library.
但我宁愿不对库中的每个文件都这样做。
How can I fix this?
我怎样才能解决这个问题?
采纳答案by RyanM
Figured it out.
弄清楚了。
All you have to do is add the -I flag to your build setting under "Other C Flags"
您所要做的就是将 -I 标志添加到“其他 C 标志”下的构建设置中
So in your target's build setting search for "Other C Flags" and add -I/path-to-include/
因此,在目标的构建设置中搜索“Other C Flags”并添加 -I/path-to-include/
Here's a screenshot:

这是一个屏幕截图:

回答by John Clements
In version 5.0.2 of XCode, the best way to accomplish this is probably to add it to the target's "Search Paths" pane. Locating this was (for me) incrediblyunintuitive. Here's how I got to it, for those as confused as I:
在 XCode 5.0.2 版本中,完成此操作的最佳方法可能是将其添加到目标的“搜索路径”窗格中。定位这个(对我来说)非常不直观。对于那些和我一样困惑的人,我是这样理解的:
In the left column, click on the Project Navigator icon (looks like a folder). Then, click on the project entry. This should show a bunch of settings in the main pane. At the top of this pane, click on "Build Settings. This shows a bunch of entries... including one called Search Paths... but you can't add a search path here! This made me gnash my teeth for quite a while, until I figured out that the name of the project at the top of this pane was a pull-down; choose the targetfrom this pull-down, and you should now be able to double click on "Header Search Paths" and perform the needed edit.
在左栏中,单击 Project Navigator 图标(看起来像一个文件夹)。然后,单击项目条目。这应该在主窗格中显示一堆设置。在此窗格的顶部,单击“构建设置”。这会显示一堆条目……包括一个名为“搜索路径”的条目……但您无法在此处添加搜索路径!这让我咬牙切齿同时,直到我发现此窗格顶部的项目名称是一个下拉列表;从该下拉列表中选择目标,您现在应该可以双击“标题搜索路径”并执行所需的编辑。
Oh, the joy of crazy GUIs.
哦,疯狂的 GUI 带来的乐趣。
回答by russes
Try this:
尝试这个:
1 - select your project file in the left Xcode pane
2 - make sure your project is selected in the middle Xcode pane
3 - select "Build Settings" at the top of the middle Xcode pane
4 - be sure "All" & "Combined" are selected just beneath "Build Settings"
5 - type header in the search field just below "Build Settings"
1 - 在左侧 Xcode 窗格中选择您的项目文件
2 - 确保在中间的 Xcode 窗格中选择您的项目
3 -在中间的 Xcode 窗格中选择“Build Settings”
4 - 确保“All”和“Combined”在“构建设置”下方选择
5 -在“构建设置”正下方的搜索字段中键入标题
You should see the search path fields ready for editing in the middle pane.
您应该会在中间窗格中看到可供编辑的搜索路径字段。
回答by Matt
I solved this in Xcode 5.0.1 using the project Build Settings (as John and Ian noted above, but I cannot comment due to <50 rep).
我在 Xcode 5.0.1 中使用项目 Build Settings 解决了这个问题(正如 John 和 Ian 上面提到的,但由于 <50 rep 我无法评论)。
New info:
新信息:
When adding includes to UserHeader Search Paths, I also had to change Always Search User Paths to Yes.
将包含添加到用户标题搜索路径时,我还必须将始终搜索用户路径更改为是。
When adding includes to (non-User) Header Search Paths, Always Search User Paths is not required.
向(非用户)标题搜索路径添加包含时,不需要始终搜索用户路径。
回答by imallett
Although this works, it is probably better to put it under the "Search Paths" tab instead.
尽管这有效,但最好将其放在“搜索路径”选项卡下。
回答by parasrish
Either you can use "Other C Flags" or use "HEADER_SEARCH_PATHS", to specify the include paths, to look for header for your executable.
您可以使用“其他 C 标志”或使用“HEADER_SEARCH_PATHS”来指定包含路径,以查找可执行文件的标头。

