Where are the headers of the C++ standard library

Viewed 77563

I wonder where on my file system I find the headers of the C++ Standard library. In particular I am looking for the definition of the vector template. I searched in /usr/include/ and various subdirectories. I also tried 'locate vector.h' which brought up many implementations of vectors, but not the standard one. What am I missing? (The distribution is Gentoo)

Background: I'm profiling a library that iterates over vector's most of the time and gprof shows that most of the time is spent in

std::vector<int, std::allocator<int> >::_M_insert_aux(
  __gnu_cxx::__normal_iterator<int*, std::vector<
      int, std::allocator<int> > >, int const&)

Probably this is what happens internally on a std::vector::push_back, but I'm not sure.

6 Answers

The file location is actually compiler-dependent.

You can use the bash tool "locate" to search for any of the files that you know are in the library. eg. "locate stl_multimap.h" for me yields:

/usr/include/c++/5/bits/stl_multimap.h
/usr/include/c++/6/bits/stl_multimap.h
/usr/include/c++/7/bits/stl_multimap.h
/usr/include/c++/8/bits/stl_multimap.h
/usr/lib/gcc-snapshot/include/c++/9/bits/stl_multimap.h

Once you have a look at the directories it should become pretty obvious where everything else is too.

In each of those locations I'll find the different compiler versions of the file. For my computer, all the gcc 7.* files are in my /usr/include/c++/7 directory.

If for some horrible reason you use Windows, I'm sure that you'll be able to find an equivalent command with Powershell.

Related