Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to determine the directories from where "#include <.....>" gets the header files?

Reply
Thread Tools

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

 
 
Pablo Suarez
Guest
Posts: n/a
 
      05-18-2008
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

 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      05-18-2008
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
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      05-18-2008
On 18 mai, 04:01, (E-Mail Removed) (Pablo Suarez) wrote:
> When I code


> #include "myheader.h"


> then this header file is searched in the current directory.


Not with the compilers I use. The de facto standard is to first
look for it in the directory which contained the file containing
the header declaration.

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


> #include <myheader.h>


> instead?


Where ever it wants to. In theory, at least, there may not even
be a file. (As far as the standard is concerned, you can only
use this form for the standard headers.)

According to the standard, the compiler has two different rules,
one for looking up "...", and another for looking up <...>, and
the second need not even be a file; the compiler could "know"
the contents of all of the standard headers, and simply
incorporate that knowledge directly. In addition, the standard
says that if lookup for "..." fails, the compiler must attempt
again as if it were <...>.

In practice, the rules are:

-- if the "header.hh" form is used, look in the directory
containing the file with the include, then

-- look in each of the directories specified by the -I or /I
options, in the order the options appeared, and finally

-- look in a number of predefined locations---under Unix, this
is typically some locations depending on where the compiler
is installed, plus /usr/include.

In practice, too, that's just a minimal set. A lot of compilers
have additional options or rules.

--
James Kanze (GABI Software) email:(E-Mail Removed)
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
 
Reply With Quote
 
Ulrich Eckhardt
Guest
Posts: n/a
 
      05-18-2008
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 <Y> and if necessary adjust the compiler settings to include that
library.

Uli

 
Reply With Quote
 
Shen-Ou YE
Guest
Posts: n/a
 
      05-19-2008
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, ...
 
Reply With Quote
 
asm23
Guest
Posts: n/a
 
      05-19-2008
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.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      05-19-2008
On May 19, 2:38 am, Shen-Ou YE <(E-Mail Removed)> wrote:
> 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:(E-Mail Removed)
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

 
Reply With Quote
 
Fred
Guest
Posts: n/a
 
      05-19-2008
On May 17, 7:01*pm, (E-Mail Removed) (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

 
Reply With Quote
 
sk_usenet
Guest
Posts: n/a
 
      05-19-2008
"Pablo Suarez" <(E-Mail Removed)> wrote 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


 
Reply With Quote
 
Gerhard Wolf
Guest
Posts: n/a
 
      05-20-2008
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 ..)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Multiple bin-directories with virtual directories? =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?= ASP .Net 0 11-09-2004 05:49 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM
Using virtual directories for common directories (scripts, images, styles, etc.) Jeffry van de Vuurst ASP .Net 2 07-30-2003 07:00 PM



Advertisments