Adding a system header search path to Xcode

(By posting this question for reference, I will answer immediately)

How to add header search paths to Xcode? Especially if you enable this syntax:

include <myheader.h> 
  • Adding a path globally to all projects, such as system headers.
  • Adding a path only to a specific project.
+48
search path header xcode system
Aug 6 2018-10-10T00:
source share
4 answers

We have two options.

  • Look at Preferences-> Locations β†’ "Source Trees" in Xcode Preferences. The path added here will be a system level path and is available for inclusion for all projects.

  • Set the HEADER_SEARCH_PATHS parameter in the build settings in the project information. I added "${SRCROOT}" here without recursion. This option is suitable for most projects.

About the second option:

Xcode uses Clang, which has a GCC-compatible command. GCC has the -Idir option , which adds search paths to the system header. And this parameter is available through HEADER_SEARCH_PATHS in the build configuration of the Xcode project.

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

But some OS X users (like me) can put their projects on the path, including spaces that need to be escaped . You can avoid it like /Users/my/work/a\ project\ with\ space if you enter it manually. You can also escape them with quotes to use an environment variable such as "${SRCROOT}" .

Or just use it . to indicate the current directory. I saw this trick in the Webkit source code, but I'm not sure that the current directory will be installed in the project directory when it is created.

${SRCROOT} - A predefined value by Xcode. This means the source directory. You can find more values ​​in the Reference Document .

PS. You really don't need to use curly braces {} . I get the same result with $SRCROOT . If you know the difference, let me know.

+94
Aug 6 2018-10-10T00:
source share

Stay tuned for Eonil answers regarding project level settings. When the selected object is selected and the Assembly Settings tab is selected, no link can be specified in the Search Paths for Header Search Paths list. In this case, you can go to "Everyone" with "Basic" in the search bar, and in the "Search paths" section, heading search paths will appear.

+10
Aug 05 2018-11-11T00:
source share

Although this question has an answer, I solved it differently when I had the same problem. I had this problem when I copied folders with the Create Folder references option; then the above solution worked on adding a folder to the build_path file. But when the folder was added using the Create groups for any added folder option, the headers were automatically selected.

+3
Jan 19 '12 at 8:12
source share

To use quotation marks for completeness only.

"/Users/my/work/a project with space"/**

If not recursive, remove /**

+2
Apr 05 2018-11-11T00:
source share



All Articles