6

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++

madmik3
  • 6,975
  • 3
  • 38
  • 60

3 Answers3

6

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
  • 398,885
  • 90
  • 523
  • 479
1

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
  • 510,854
  • 105
  • 1,084
  • 1,005
0

Also of relevance

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

JeremyP
  • 84,577
  • 15
  • 123
  • 161