Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the headers of the C++ standard library

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.

like image 871
Thomas Avatar asked Jul 12 '12 17:07

Thomas


People also ask

Where can I find C header files?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.

What is C standard library and header files?

C Standard library functions or simply C Library functions are inbuilt functions in C programming. The prototype and data definitions of these functions are present in their respective header files. To use these functions we need to include the header file in our program.

What is standard library header files?

In C language, header files contain the set of predefined standard library functions. The “#include” preprocessing directive is used to include the header files with “. h” extension in the program.

How many header files make up the standard C library?

The ANSI C standard library consists of 24 C header files which can be included into a programmer's project with a single directive. Each header file contains one or more function declarations, data type definitions and macros.


2 Answers

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.

like image 67
Mike Seymour Avatar answered Sep 18 '22 20:09

Mike Seymour


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

like image 28
R. Martinho Fernandes Avatar answered Sep 20 '22 20:09

R. Martinho Fernandes