将系统头搜索路径添加到 Xcode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3428216/
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
Adding system header search path to Xcode
提问by Eonil
(Posting this question for reference purpose, I'll answer immediately)
(发布此问题以供参考,我会立即回答)
How to add header search paths to Xcode? Especially when including with this syntax:
如何将标题搜索路径添加到 Xcode?特别是在包含以下语法时:
include <myheader.h>
- Adding path globally to all projects like system headers.
- Adding path to only to a specific project.
- 将路径全局添加到所有项目,如系统标题。
- 仅将路径添加到特定项目。
回答by Eonil
We have two options.
我们有两个选择。
Look at Preferences->Locations->"Source Trees" in Xcode's preference. A path added here will be a system-level path and available to be included for all projects.
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 的首选项中查看 Preferences->Locations->"Source Trees"。此处添加的路径将是系统级路径,可用于所有项目。
HEADER_SEARCH_PATHS
在项目信息的构建设置中设置参数。我"${SRCROOT}"
在这里添加了没有递归。此设置适用于大多数项目。
About 2nd option:
关于第二个选项:
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.
Xcode 使用具有 GCC 兼容命令集的 Clang。
GCC 有一个选项-Idir
可以添加系统标题搜索路径。此选项可通过HEADER_SEARCH_PATHS
Xcode 项目构建设置访问。
However, path string added to this setting should not contain any whitespace characters because the option will be passed to shell command as is.
但是,添加到此设置的路径字符串不应包含任何空格字符,因为该选项将按原样传递给 shell 命令。
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}"
.
但是,一些 OS X 用户(比如我)可能会将他们的项目放在路径上,包括应该转义的空格。您可以像/Users/my/work/a\ project\ with\ space
手动输入一样转义它。您也可以用引号将它们转义以使用环境变量,如"${SRCROOT}"
.
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.
或仅用于.
指示当前目录。我在 Webkit 的源代码上看到了这个技巧,但是我不确定在构建它时当前目录是否会设置为项目目录。
The ${SRCROOT}
is predefined value by Xcode. This means source directory. You can find more values in Reference document.
的${SRCROOT}
是通过Xcode的预定义值。这意味着源目录。您可以在参考文档中找到更多值。
PS. Actually you don't have to use braces {}
. I get same result with $SRCROOT
. If you know the difference, please let me know.
附注。实际上,您不必使用大括号{}
。我得到相同的结果$SRCROOT
。如果你知道区别,请告诉我。
回答by Prof Von Lemongargle
Follow up to Eonil's answer related to project level settings. With the target selected and the Build Settings tab selected, there may be no listing under Search Paths for Header Search Paths. In this case, you can change to "All" from "Basic" in the search bar and Header Search Paths will show up in the Search Paths section.
跟进 Eonil 与项目级别设置相关的回答。选择目标并选择构建设置选项卡后,标题搜索路径的搜索路径下可能没有列表。在这种情况下,您可以从搜索栏中的“基本”更改为“全部”,标题搜索路径将显示在“搜索路径”部分。
回答by ToothlessRebel
To use quotes just for completeness.
使用引号只是为了完整性。
"/Users/my/work/a project with space"/**
"/Users/my/work/a project with space"/**
If not recursive, remove the /**
如果不是递归的,删除 /**
回答by roshi
Though this question has an answer, I resolved it differently when I had the same issue. I had this issue when I copied folders with the option Create Folder references
; then the above solution of adding the folder to the build_path worked.
But when the folder was added using the Create groups for any added folder
option, the headers were picked up automatically.
虽然这个问题有答案,但当我遇到同样的问题时,我以不同的方式解决了它。当我使用选项复制文件夹时遇到了这个问题Create Folder references
;然后将文件夹添加到 build_path 的上述解决方案有效。但是当使用该Create groups for any added folder
选项添加文件夹时,会自动选取标题。