468,310 Members | 1,425 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,310 developers. It's quick & easy.

How to determine the directories from where "#include <.....>" gets the header files?

When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?

Pablo

Jun 27 '08 #1
12 2219
Sam
Pablo Suarez writes:
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?
Each compiler has its on preconfigured list of directories which it searches
for the header files. This is a compiler-specific setting. Check the
documentation for your compiler if you need to know what they are.

Most compilers recognize the -I option that adds a directory to the list of
directories it searches for header files. Incidentally, if the compiler does
not find "filename.h" in the current directory (actually, not the current
directory, but the directory where the source file, that referenced this
header file, is located), it continues to search for filename.h in the same
list of directories. The only actual difference between "filename.h" and
<filename.his that the former one is searched for in the source directory
first.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBIL5AUx9p3GYHlUOIRAm8oAJ0R1AmBVivAlOTO1pHWIp 77jKgmIgCeO2H0
eugRkuTsFq3oKysXEgfosi4=
=gKNy
-----END PGP SIGNATURE-----

Jun 27 '08 #2
Pablo Suarez wrote:
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?
Depends on the compiler. However the compiler is set up to search for them.
Standard library header directories, etc...

Are you asking what the standard says about this, how to determine for your
specific compiler or something else?

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #3
Pablo Suarez wrote:
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?
There are two answers to this, one as given by the C and C++ language
standards and one that applies in reality.

1. The language defines several so-called headers like <stdio.h(C) or
<iostream(C++). These are not ever required to be files at all, it is
only required to have certain effects if you include them. In reality, most
compilers install these headers as part of the compiler installation.

2. In practice, you will find in the same dir as other compiler-supplied
headers are installed in also some files that are system-dependent.
Further, often libraries install their header files in that dir or add a
directory with their headers to the path searched for system include files.

Suggestion: if file X includes file Y, use #include "Y" if Y is part of the
same program or library as X. If Y belongs to a separate library, use
#include <Yand if necessary adjust the compiler settings to include that
library.

Uli

Jun 27 '08 #4
Pablo Suarez wrote:
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?

Pablo
Hi,

When you write :

#include <myheader.h>

myheader.h is searched in the default system include directories. Under
Unix, it's typically /usr/include, /usr/X11/include, ...
Jun 27 '08 #5
Pablo Suarez wrote:
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?

Pablo
hi, each compiler will put the standard header files in some directory
,eg, I'm using Visual c++, the directory is something like Microsoft
Visual Studio\VC98\INCLUDE...
so, depend on the compiler you use, you can find them. Also, with -I,
you can specifies an additional directory to search for include files.
Jun 27 '08 #6
On May 19, 2:38 am, Shen-Ou YE <shenou...@gmail.comwrote:
Pablo Suarez wrote:
When I code
#include "myheader.h"
then this header file is searched in the current directory.
But where does the compiler search the header file when I write
#include <myheader.h>
instead?
When you write :
#include <myheader.h>
myheader.h is searched in the default system include
directories. Under Unix, it's typically /usr/include,
/usr/X11/include, ...
Not only. First, any directories specified by -I are searched,
then some compiler specific directories
("/opt/SUNWspro/include", for example, or
"~/gnu/gcc/install-4.1.0/include"), and finally the default
system directories (usually just "/usr/include"). Of course,
the first form of the include will search all these as well, if
it doesn't find the file in the directory where the source file
including it is located.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 27 '08 #7
On May 17, 7:01*pm, pcs...@yahoo.com (Pablo Suarez) wrote:
When I code

#include "myheader.h"

then this header file is searched in the current directory.
Almost. It is *first* looked for in the current directory.
If not found, it *may* be looked for in other places,
according to implementation-dependent rules.
>
But where does the compiler search the header file when I write

#include <myheader.h>

instead?
It is looked for in implementation-defined "standard" directories.
ON *nix, this is usually /usr/include.

Also, most compilers allow command-line options to specify
additional directories to be searched BEFORE the standard place(s),
using the -I option:
cc -I/MyDirectory -I/MyOtherDirectory ...

These directories will be searched for with either of the #include
styles.
--
Fred Kleinschmidt

Jun 27 '08 #8
"Pablo Suarez" <pc****@yahoo.comwrote in message
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?
You specify it to the compiler. Check your compiler's documentation as to
how you control it so search directories for header files. With gcc the
option is -I.

--
http://techytalk.googlepages.com
Jun 27 '08 #9
Pablo Suarez schrieb:
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?

Pablo
INCLUDE Environment variable or compiler searchpath (-I ..)
Jun 27 '08 #10
On May 19, 8:36 pm, Fred <fred.l.kleinschm...@boeing.comwrote:
On May 17, 7:01 pm, pcs...@yahoo.com (Pablo Suarez) wrote:
When I code
#include "myheader.h"
then this header file is searched in the current directory.
Almost. It is *first* looked for in the current directory.
If not found, it *may* be looked for in other places,
according to implementation-dependent rules.
It's very much compiler dependent, but I don't know of any which
look in the current directory (unless you specifically tell the
compiler to do so).
But where does the compiler search the header file when I write
#include <myheader.h>
instead?
It is looked for in implementation-defined "standard" directories.
ON *nix, this is usually /usr/include.
Again, it's very implementation dependent, and almost always
includes more than just /usr/include.
Also, most compilers allow command-line options to specify
additional directories to be searched BEFORE the standard place(s),
using the -I option:
cc -I/MyDirectory -I/MyOtherDirectory ...
These directories will be searched for with either of the
#include styles.
The rules say that for an "..." include, if the search fails,
the compiler must then treat it as a <...include.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #11
On Mon, 19 May 2008 15:18:14 -0700, sk_usenet wrote:
"Pablo Suarez" <pc****@yahoo.comwrote in message
>When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?

You specify it to the compiler. Check your compiler's documentation as
to how you control it so search directories for header files. With gcc
the option is -I.
Further to this: if you want to know where the current invocation of g++
is searching for headers (system and other), specify the -v option on the
g++ command.

--
Lionel B
Jun 27 '08 #12
On May 17, 9:01*pm, pcs...@yahoo.com (Pablo Suarez) wrote:
When I code

#include "myheader.h"

then this header file is searched in the current directory.

But where does the compiler search the header file when I write

#include <myheader.h>

instead?

Pablo
Pablo,

I belive, if I'm not mistaken, it searches the current directory.
Jun 27 '08 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by steve | last post: by
18 posts views Thread by Exits Funnel | last post: by
18 posts views Thread by Tuckers | last post: by
7 posts views Thread by Matt Jensen | last post: by
1 post views Thread by Andrew | last post: by
4 posts views Thread by John Smith | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.