views:

120

answers:

4

I can only find a little bit of information on the topic. My understand right now is that

#import <my.h> // searches in the system paths
#import "my.h" // searches in the same dir as the source file - is that right?

I have an static library with .h files in a different location. Can I have the compiler search a new folder for .h files with #import "my.h" like I would in VC++

A: 

I think this post is relevant.

Rob
+1  A: 

In Objective-C, #import is just #include which will include each file once only. So it will follow #include rules in searching the file.

The <…> indicates system headers and "…" user headers. Which path the preprocessor will look into depend on the your settings. For GCC, <…> will look in:

 /usr/local/include
 <libdir/gcc/target/version>/include
 /usr/<target>/include
 /usr/include

and also the paths added by the -I and -F switches. "…" will look in current directory, and then those added by the -iquote switch, and then the system paths.

See http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html for detail.

KennyTM
+2  A: 

Your understanding is pretty much correct, except that #import "my.h" searches in the same directory as the source file, and all the system paths (the same ones searched by #import <my.h>).

I have an static library with .h files in a different location. Can I have the compiler search a new folder for .h files with #import "my.h" like I would in VC++

Yes. You have to pass the -I flag to gcc. For example, if you want to search path/to/my-other-dir, you'd pass -Ipath/to/my-other-dir to gcc. If you're using Xcode, you can configure this using the build options for your target; look for the option called Header Search Paths, under Search Paths.

mipadi
A: 

Also of relevance

http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html

JeremyP