How to set include path in xcode project

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

The directory structure of the libraries is as follows:

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

The docs library says it includes file1.h, and file1.h includes file2.h and file3.h.

I get "file not found" errors for inclusions file2.h and file3.h`. They are included by file1.h as follows:

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

I read here that these angle brackets instruct the preprocessor to search for included files in the path specified by the INCLUDE environment variable, as opposed to searching in the same directory as the file containing #include.

So, I added the INCLUDE environment variable to Xcode by going to Product-> Edit Scheme .. and setting it to /the-whole-path-to/include/ , however I still get a file that was not found by errors.

Files are successfully included if I modify file1.h to include them as follows:

 #include "file2.h" 

but I would prefer not to do this for every file in the library.

How can i fix this?

+47
c include xcode environment-variables
Jan 03 '13 at 6:28
source share
6 answers

Figured it out.

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

So, in your target build setup, find “Other C Flags” and add -I/path-to-include/

Here is a screenshot: enter image description here

+45
Jan 04 '13 at 7:34
source share

In version 5.0.2, Xcode the best way to accomplish this is probably to add it to the Search Paths target panel. Finding it was (for me) incredibly unintuitive. Here is how I got to him, for those who were embarrassed, like me:

In the left column, click the Project Navigator icon (looks like a folder). Then click on the project entry. This should show a bunch of settings in the main panel. At the top of this panel, click Build Settings. This shows a bunch of entries ... including one of them "Search Paths" ... but you cannot add a search path here! This made me grip my teeth for quite a while until I realized that the project name at the top of this panel was a drop-down, select a target from this drop-down list, and now you can double-click “Title Search Paths” and do the necessary editing.

Oh, the joy of crazy GUIs.

+48
Dec 31 '14 at 19:47
source share

I solved this in Xcode 5.0.1 using the Build project settings (as John and Ian pointed out, but I can not comment because of 50 reps).

New information:

When adding user headers to search paths, I also need to change the search path always to users.

When added to search paths (not for the user), user paths are always searched.

+10
Jan 20 '14 at 6:28
source share

Although this works, it's probably best to place it under the Search Paths tab.

+4
Sep 18 '13 at 19:13
source share

Try the following:

1 - select the project file in the left pane of Xcode
2 - make sure your project is selected in the middle area of ​​Xcode
3 - select “Build Settings” at the top of the Xcode middle pane
4 - make sure that “All” and “Combined” are selected only under “Build Settings”
5 - type header in the search box just below "Build Settings"

You should see the search path fields ready for editing in the middle pane.

+4
Mar 11 '16 at 1:31
source share

Either you can use Other C Flags, or use HEADER_SEARCH_PATHS to specify the paths included to search for a header for your executable.

+2
Aug 27 '15 at 16:22
source share



All Articles