How to determine the directories from where "#include <.....>" gets the header files? 
June 27th, 2008, 05:43 PM
| | | |
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 | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
Pablo Suarez writes: Quote:
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----- | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
Pablo Suarez wrote: Quote:
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 tazmaster@rocketmail.com | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
Pablo Suarez wrote: Quote:
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 | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
Pablo Suarez wrote: Quote:
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, ... | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
Pablo Suarez wrote: Quote:
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. | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
On May 19, 2:38 am, Shen-Ou YE <shenou...@gmail.comwrote: Quote: Quote: |
then this header file is searched in the current directory.
| | Quote: Quote: |
But where does the compiler search the header file when I write
| | Quote:
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:james.kanze@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 | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
On May 17, 7:01*pm, pcs...@yahoo.com (Pablo Suarez) wrote: Quote:
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. Quote:
>
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 | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
"Pablo Suarez" <pcsuar@yahoo.comwrote in message Quote:
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 | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
Pablo Suarez schrieb: Quote:
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 ..) | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
On May 19, 8:36 pm, Fred <fred.l.kleinschm...@boeing.comwrote: Quote: |
On May 17, 7:01 pm, pcs...@yahoo.com (Pablo Suarez) wrote:
| Quote: Quote: |
then this header file is searched in the current directory.
| | Quote:
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). Quote: Quote: |
But where does the compiler search the header file when I write
| | Quote:
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. Quote:
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 ...
| Quote:
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:james.kanze@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 | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
On Mon, 19 May 2008 15:18:14 -0700, sk_usenet wrote: Quote:
"Pablo Suarez" <pcsuar@yahoo.comwrote in message Quote:
>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 | 
June 27th, 2008, 05:43 PM
| | | | re: How to determine the directories from where "#include <.....>" gets the header files?
On May 17, 9:01*pm, pcs...@yahoo.com (Pablo Suarez) wrote: Quote:
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. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|