473,651 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2547
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)

iD8DBQBIL5AUx9p 3GYHlUOIRAm8oAJ 0R1AmBVivAlOTO1 pHWIp77jKgmIgCe O2H0
eugRkuTsFq3oKys XEgfosi4=
=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*******@rocke tmail.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\INC LUDE...
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...@gmai l.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 objektorientier ter Datenverarbeitu ng
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.co m (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/MyOtherDirector y ...

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

Jun 27 '08 #8
"Pablo Suarez" <pc****@yahoo.c omwrote 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
5081
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is relative NOT to the immediate script that is including it, but is relative to the top-level calling script. In practice, this means that you have to constantly worry and adjust paths in includes, based on the startup scripts that call these...
3
9380
by: Michael | last post by:
There seem to be two ways to include files on the server: 1. <!-- #include file="header.inc" --> 2. <script language="VBScript" runat="server" src="header.inc"></script> What are the differences between the two, and when to use one instead of the other? Thanks.
7
3545
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout way to do this in 3 steps: 1. Add in main_file.cpp
18
2242
by: Exits Funnel | last post by:
Hello, I'm a little confused about where I should include header files and was wondering whether there was some convention. Imagine I've written a class foo and put the definition in foo.h and the implementation of its member functions in foo.cpp (which obviously #inludes foo.h) and further assume that it depends on a class bar which is defined in bar.h. It seems that there are the following two scenarios:
18
2623
by: Tuckers | last post by:
My question is, if I have created my own library which lives in its own install directory, to refer to its header file is it better to use #include "MyLibrary.h" or #include <MyLibrary.h> Assume that this library will be used by other groups. I think the answer
7
2231
by: Matt Jensen | last post by:
Howdy I want to simulate with .Net what I used to do with classic ASP where you would have a series of include files with utility functions that you would include when you needed them. I read some article about creating a utility class, but it gave no details, and I'm not sure what to do. Do I create a .cs file and then just include it? What should the class inherit from? And how do you inherit more than one class on your page in...
1
1482
by: Andrew | last post by:
Hello, friends, In ASP, we use <!-- include --> to include header/footer files. What are recommended to do in ASP.net? Any sample source code or reference papers? Thanks a lot for your help.
4
2247
by: John Smith | last post by:
I have a project that consists of about a dozen translation units. I use a command line compiler and it occured to me that I could simplify compiling the project by #include(ing) them in a header that looks something like this: /* project.h */ #include "aaa.c" #include "bbb.c" #include "ccc.c" ....
1
4154
by: Colin Caughie | last post by:
Is there a general rule/convention for when to use angle brackets and when to use quotes in #include statements? Is the angle bracket reserved for "system" header files (e.g. standard library headers), or is it for general "stable" include files? What about the grey areas in between these and actual application code, e.g. headers for a library that is under my control but external to the project being compiled? I know both styles...
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8579
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.