I am new to C++.
What is the difference between including the c++ header files using "" and <>
I am trying to use some of the header files form an open source library. All header files in that library are included using <>. Now when I do the same in my header file, its failing at compile time.
<> looks firstly in the header path for the header file whereas "" looks firstly in the current directory of the file for the header.
The distinction is very largely implementation defined; the "..."
form
should look first in the place where the file which includes it is
situated; the <...>
no. Beyond that, both look in an implementation
defined list of places, with the additional requirement that if the
compiler doesn't find a "..."
form in any of the expected places, it
reprocesses the include as if it were a <...>
form.
In practice, all of the compilers I know build a list of places using
the -I
or /I
options, followed by a number of "standard" and
compiler defined places. This list is for <...>
; "..."
is searched
in the same directory as the including file, then treated as a <...>
.
(Some compilers, at least, also have options to add to the list for
"..."
.)
I'm not sure what's happening with regards to the library. Normally,
when using a third party library, you have to add one or more -I
or
/I
options to tell the compiler where to find its headers. Once
you've done that, both your code and the library code should find all of
the necessary headers. The one case I can think of where an include
might work in a library header, and not in your own headers, is a
"..."
style include in a library header which was included from
another library header, using a path specifier, e.g.:
LibraryFile1.hpp:
#include "Subdir/LibraryFile2.hpp"
LibraryFile2.hpp:
#include "LibraryFile3.hpp"
You will have told the compiler to look for the headers (using a -I
option) in something like LibraryRoot/include
, which is where
LibraryFile1.hpp
is located; LibraryFile2.hpp
is relative to this
location, and in LibraryFile2.hpp
, the compiler finds
LibraryFile3.hpp
because it is in the same directory as the file which
includes it. If you try to include LibraryFile3.hpp
directly,
however, the compiler won't find it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With