38

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.

jww
  • 97,681
  • 90
  • 411
  • 885
Thomas
  • 2,093
  • 3
  • 23
  • 28

6 Answers6

46

GCC typically has the standard C++ headers installed in /usr/include/c++/<version>/. You can run gcc -v to find out which version you have installed.

At least in my version, there is no vector.h; the public header is just vector (with no extension), and most of the implementation is in bits/stl_vector.h.

That's the case on my Ubuntu distribution; your distribution may differ.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • 1
    Thanks, the missing .h ws the essential hint. On Gentoo it's in /usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4/vector – Thomas Jul 12 '12 at 18:01
13

Running g++ -v -v -v outputs lots of things, including all the include directories searched. vector is in one of those.

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
3

On my Debian Stable system vector is here:

/usr/include/c++/4.4/vector
genpfault
  • 51,148
  • 11
  • 85
  • 139
2

On a "plain" ubuntu install you have to install

libstdc++-version-dev

to get the header files.

then cheking the installed files you'll get the path !

Reinstate Monica
  • 588
  • 7
  • 21
jo_
  • 171
  • 1
  • 2
1

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.

Elliott
  • 2,603
  • 2
  • 18
  • 35
  • On MacOSX13 I have to drop the `.h` and use `locate iostream | grep Library` to find the correct location, which for me seems to be `/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/iostream` – Will Jul 19 '23 at 08:19
  • Update: Using R. Martinho Fernades's suggestion below, the comand `g++ -v` show me the actual correct location being used by clang, namely: `InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin` from which one can deduce and find the include location to be: `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream` – Will Jul 19 '23 at 08:25
0

In many IDE (e.g. NetBeans) you may use Ctrl+Click to className to go to definition

RiaD
  • 46,822
  • 11
  • 79
  • 123