I want to begin my question with a disclaimer that I am beginner with c++.
My question is how does the preprocessor know which directories to look for when looking for header file.
I know that it searches in some specific predefined locations and whatever we pass as -I in the g++ compilation step. However what confuses me is some standard headers are picked up even if they are not in those locations.
I referred to the question at Finding out what the GCC include path is and I followed the steps there.
$ /usr/include % echo | cpp -Wp,-v
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.9/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "<stdin>"
But I tried to locate the iostream and I see
$ locate iostream
/usr/include/c++/4.8/iostream
it is located at /usr/include/c++/4.8/iostream
, but the search path ends at /usr/include
. If it were any other header file, I would have to include it as
#include <c++/4.8/iostream>
, but in all the programs I use #include <iostream>
.
PS: The reason I am asking this question is because I accidentally deleted /usr/include/c++/4.9
directory, it used to work before deleting. But it is not picking up usr/include/c++/4.8/cstddef
. I want to understand the procedure for picking up correct include paths of c++ preprocessor.
Thanks