Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <include.hpp> and "include.hpp" [duplicate]

Tags:

c++

include

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.

like image 365
M99 Avatar asked Sep 13 '11 15:09

M99


2 Answers

<> looks firstly in the header path for the header file whereas "" looks firstly in the current directory of the file for the header.

like image 85
DrYap Avatar answered Oct 11 '22 00:10

DrYap


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.

like image 28
James Kanze Avatar answered Oct 11 '22 00:10

James Kanze