25

I often see open source code importing third-party libraries in Xcode / Objective-C implementation files like this:

#import <ThirdPartyLibrary/utilities.h>

but when I drag & drop the file structure and files of such a library in my project, all these imports are corrupted and Xcode does not know where the files are.

I end up hand-modifying every import to look like:

#import "utilities.h"

And include appears it is relative to the current physical folder on the file system. When a library split its files in folders on file system and I drag-drop it in Xcode, Xcode creates groups for the folders. But for import, I have to specify the folder name. Problem is when I am in a folder, for example:

http/httpTools.h

Then when httpTools.h wants to import utilities.h from the root, I have to change

#import <ThirdPartyLibrary/utilities.h>

to

#import "../utilities.h"

which is a chore. After doing this for 5 hours I thought damn, there must be a better way. Can someone explain what is the secret to teaching Xcode a new framework location that can be imported with angle brackets? The framework btw is source code. Not compiled. Just the naked code.

openfrog
  • 40,201
  • 65
  • 225
  • 373
  • 2
    It's not Xcode, it's rather the compiler. Anyway, you have to extend the header file search path of the compiler; this can be done by specifying the `-I` compiler flag in the case of GCC and Clang. –  Aug 02 '13 at 21:16
  • I had a similar problem, rather than dragging in the files, include relevant directories in the header search paths xcode setting. – Justin Meiners Aug 02 '13 at 21:20
  • Are you importing the 3rd party framework or the full source code? – Wain Aug 02 '13 at 21:20
  • 1
    @H2CO3 how would you specify it for a library called "TheLibrary", and where do you put that compiler flag? – openfrog Aug 02 '13 at 21:39
  • @openfrog `clang -I/path/to/TheLibrary` etc. And compiler flags are to be put into the invocation of the compiler command line. If you are using Xcode, there's probably a section in the build settings called "include paths" or something like that. –  Aug 02 '13 at 21:42

2 Answers2

11

Specify the include path using the compiler flag -I, or the Xcode build settings alias HEADER_SEARCH_PATHS. Of course, you can use build variables when doing so.

justin
  • 104,054
  • 14
  • 179
  • 226
  • 3
    not working in my case. It seems xcode only searches from system library for headers specified between brackets. – zell Jun 02 '14 at 13:23
  • You can't just add `include`. Use `$(SRCROOT)/include/` instead. – Jeff Jun 07 '14 at 01:12
  • HEADER_SEARCH_PATHS did NOT work for me for an unknown reason. Adding -I as a compiler flag worked though. – Benjamin Piette Jan 18 '16 at 12:12
  • @BenjaminPiette that's strange -- perhaps the setting was defined at another level in Xcode's build settings? – justin Jan 31 '16 at 00:40
7

Just stumbled upon the same issue, there are two types of search paths in Xcode:

Header Search Paths
User Header Search Paths

If you add your own include folders into Header Search Paths, you can use angled brackets.

fatihk
  • 7,789
  • 1
  • 26
  • 48