如何在xcode项目中设置包含路径?

时间:2022-03-15 01:21:44

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 here that 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.

因此,我在Xcode中加入了包含环境变量的产品->编辑方案。然后把它设置为/全路径- - - /包括/但是,我仍然得到文件没有发现错误。

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?

我怎么解决这个问题?

6 个解决方案

#1


46  

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) incredibly unintuitive. 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 target from 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.

哦,疯狂的GUIs的快乐。

#2


45  

Figured it out.

算出来。

All you have to do is add the -I flag to your build setting under "Other C Flags"

您所要做的就是在“其他C标志”下添加-I标志到您的构建设置中

So in your target's build setting search for "Other C Flags" and add -I/path-to-include/

因此,在您的目标构建设置中搜索“其他C标志”并添加-I/ pathto -include/。

Here's a screenshot: 如何在xcode项目中设置包含路径?

这里有一个截图:

#3


10  

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中使用项目构建设置解决了这个问题(正如John和Ian在上面提到的,但是由于<50代表),我无法评论。

New info:

新信息:

When adding includes to User Header Search Paths, I also had to change Always Search User Paths to Yes.

当添加到用户头搜索路径时,我也必须改变总是搜索用户路径为Yes。

When adding includes to (non-User) Header Search Paths, Always Search User Paths is not required.

当添加包括(非用户)头搜索路径时,总是不需要搜索用户路径。

#4


5  

Although this works, it is probably better to put it under the "Search Paths" tab instead.

尽管这是可行的,但最好还是把它放在“搜索路径”选项卡下。

#5


4  

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面板4 -确保选择“所有”和“结合”在“构建设置”中头5 -类型搜索框下方“构建设置”

You should see the search path fields ready for editing in the middle pane.

您应该看到在中间窗格中准备编辑的搜索路径字段。

#6


2  

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”来指定include路径,以查找可执行文件的标头。

#1


46  

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) incredibly unintuitive. 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 target from 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.

哦,疯狂的GUIs的快乐。

#2


45  

Figured it out.

算出来。

All you have to do is add the -I flag to your build setting under "Other C Flags"

您所要做的就是在“其他C标志”下添加-I标志到您的构建设置中

So in your target's build setting search for "Other C Flags" and add -I/path-to-include/

因此,在您的目标构建设置中搜索“其他C标志”并添加-I/ pathto -include/。

Here's a screenshot: 如何在xcode项目中设置包含路径?

这里有一个截图:

#3


10  

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中使用项目构建设置解决了这个问题(正如John和Ian在上面提到的,但是由于<50代表),我无法评论。

New info:

新信息:

When adding includes to User Header Search Paths, I also had to change Always Search User Paths to Yes.

当添加到用户头搜索路径时,我也必须改变总是搜索用户路径为Yes。

When adding includes to (non-User) Header Search Paths, Always Search User Paths is not required.

当添加包括(非用户)头搜索路径时,总是不需要搜索用户路径。

#4


5  

Although this works, it is probably better to put it under the "Search Paths" tab instead.

尽管这是可行的,但最好还是把它放在“搜索路径”选项卡下。

#5


4  

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面板4 -确保选择“所有”和“结合”在“构建设置”中头5 -类型搜索框下方“构建设置”

You should see the search path fields ready for editing in the middle pane.

您应该看到在中间窗格中准备编辑的搜索路径字段。

#6


2  

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”来指定include路径,以查找可执行文件的标头。