将系统头搜索路径添加到 Xcode [英] Adding system header search path to Xcode

查看:34
本文介绍了将系统头搜索路径添加到 Xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(发此问题供参考,我会第一时间回答)

(Posting this question for reference purpose, I'll answer immediately)

如何将标题搜索路径添加到 Xcode?特别是在包含以下语法时:

How to add header search paths to Xcode? Especially when including with this syntax:

include <myheader.h>

  1. 向所有项目(如系统标题)全局添加路径.
  2. 仅添加指向特定项目的路径.

推荐答案

我们有两个选择.

  1. 查看首选项->位置->自定义路径"在 Xcode 的偏好中.此处添加的路径将是一个变量,您可以将其添加到标题搜索路径"中.在项目构建设置中作为$cppheaders",如果您使用该名称保存自定义路径.

  1. Look at Preferences->Locations->"Custom Paths" in Xcode's preference. A path added here will be a variable which you can add to "Header Search Paths" in project build settings as "$cppheaders", if you saved the custom path with that name.

在项目信息的构建设置中设置 HEADER_SEARCH_PATHS 参数.我在这里没有递归地添加了 "${SRCROOT}" .此设置适用于大多数项目.

Set HEADER_SEARCH_PATHS parameter in build settings on project info. I added "${SRCROOT}" here without recursion. This setting works well for most projects.

关于第二个选项:

Xcode 使用具有 GCC 兼容命令集的 Clang.GCC 有一个选项 -Idir添加系统标题搜索路径.此选项可通过 Xcode 项目构建设置中的 HEADER_SEARCH_PATHS 访问.

Xcode uses Clang which has GCC compatible command set. GCC has an option -Idir which adds system header searching paths. And this option is accessible via HEADER_SEARCH_PATHS in Xcode project build setting.

但是,添加到此设置的路径字符串不应包含任何空格字符,因为该选项将按原样传递给 shell 命令.

However, path string added to this setting should not contain any whitespace characters because the option will be passed to shell command as is.

但是,一些 OS X 用户(像我一样)可能会将他们的项目放在包含应该转义的空格的路径上.如果你手动输入它,你可以像 /Users/my/work/a project with space 一样转义它.您也可以使用引号将它们转义以使用环境变量,例如 "${SRCROOT}".

But, some OS X users (like me) may put their projects on path including whitespace which should be escaped. You can escape it like /Users/my/work/a project with space if you input it manually. You also can escape them with quotes to use environment variable like "${SRCROOT}".

或者直接使用 . 表示当前目录.我在 Webkit 的源代码上看到了这个技巧,但我不确定在构建时将当前目录设置为项目目录.

Or just use . to indicate current directory. I saw this trick on Webkit's source code, but I am not sure that current directory will be set to project directory when building it.

${SRCROOT} 是 Xcode 预定义的值.这意味着源目录.您可以在 参考中找到更多值文档.

The ${SRCROOT} is predefined value by Xcode. This means source directory. You can find more values in Reference document.

附注.实际上,您不必使用大括号 {}.我用 $SRCROOT 得到相同的结果.如果您知道其中的区别,请告诉我.

PS. Actually you don't have to use braces {}. I get same result with $SRCROOT. If you know the difference, please let me know.

这篇关于将系统头搜索路径添加到 Xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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