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

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

问题描述



如何向Xcode添加标题搜索路径?

(将此问题作为参考用途发布,我会立即回答)
特别是当包含这个语法时:

  include< myheader.h> 




  1. 全局添加路径至所有项目,例如系统标题。

  2. 仅将路径添加到特定项目。
  3. 我们有两个选项。


    1. 查看Xcode偏好设置中的Preferences-> Locations - >Source Trees。这里添加的路径将是系统级路径,可供所有项目使用。

    2. $ c>参数在项目信息的构建设置中。我在这里添加了$ {SRCROOT}而无需递归。此设置适用于大多数项目。 b


      关于第二种选择:

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

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



      但是,一些OS X用户(如我)可能会将其项目放在包括空白哪些应该被转义。如果您手动输入它,可以像 / Users / my / work / a \ project \ with \ space 一样将其转义。您也可以使用引号将它们转义为使用环境变量,如$ {SRCROOT}



      表示当前目录。我在Webkit的源代码中看到了这个技巧,但是我不确定当前目录在构建时会被设置为项目目录。



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



      PS。其实你不必使用大括号 {} 。我得到与 $ SRCROOT 相同的结果。如果你知道区别,请告诉我。


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

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

      include <myheader.h>
      

      1. Adding path globally to all projects like system headers.
      2. Adding path to only to a specific project.

      解决方案

      We have two options.

      1. 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.

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

      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.

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

      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}".

      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.

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

      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天全站免登陆