如何在xcode项目中设置包含路径 [英] How to set include path in xcode project

查看:175
本文介绍了如何在xcode项目中设置包含路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在Objective-C Xcode项目中使用C库。

I am trying to use a C library in an Objective-C Xcode project.

库目录结构如下:

-- include/
    |-- config.h
    |-- lib/
    |    |-- file1.h
    |    |-- file2.h
    |    |-- file3.h

图书馆的文档说包含file1.h,file1.h包含file2.h和file3.h。

The library's docs say to include file1.h, and file1.h includes file2.h and file3.h.

我收到file2.h和file3.h`的file not found错误。
它们由file1.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:

#include <lib/file1.h>
#include <lib/file2.h>

我读了这里这些角括号指示预处理器沿着INCLUDE环境变量指定的路径搜索包含文件,而不是在与包含#include的文件相同的目录中进行搜索。

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.

所以我在Xcode中添加了INCLUDE环境变量,方法是进入Product-> Edit Scheme ..并将其设置为 / the-whole-path -to / 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.

如果我更改file1.h,文件成功包含包括他们如下:

The files are successfully included if I change file1.h to include them like this:

#include "file2.h"

但我宁愿不为库中的每个文件都这样做。

but I'd rather not do that for every file in the library.

如何解决这个问题?

推荐答案

所有您需要做的是将-I标志添加到其他C标志下的构建设置

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

所以在您的目标的构建设置中搜索其他C标志并添加 -I / path-to-include /

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

这是一个截图:

Here's a screenshot:

这篇关于如何在xcode项目中设置包含路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆