简体   繁体   English

C++标准库的头文件在哪里

[英]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.我想知道在我的文件系统上哪里可以找到 C++ 标准库的标头。 In particular I am looking for the definition of the vector template.特别是我正在寻找矢量模板的定义。 I searched in /usr/include/ and various subdirectories.我在 /usr/include/ 和各种子目录中搜索。 I also tried 'locate vector.h' which brought up many implementations of vectors, but not the standard one.我还尝试了“locate vector.h”,它提出了许多矢量的实现,但不是标准的。 What am I missing?我错过了什么? (The distribution is Gentoo) (发行版是 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背景:我正在分析一个大部分时间迭代 vector 的库,gprof 显示大部分时间都花在

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.可能这就是 std::vector::push_back 内部发生的情况,但我不确定。

GCC typically has the standard C++ headers installed in /usr/include/c++/<version>/ . GCC 通常在/usr/include/c++/<version>/中安装了标准的 C++ 头文件。 You can run gcc -v to find out which version you have installed.您可以运行gcc -v来查看您安装的是哪个版本。

At least in my version, there is no vector.h ;至少在我的版本中,没有vector.h the public header is just vector (with no extension), and most of the implementation is in bits/stl_vector.h .公共标头只是vector (没有扩展名),大部分实现都在bits/stl_vector.h中。

That's the case on my Ubuntu distribution;我的 Ubuntu 发行版就是这种情况; your distribution may differ.您的分布可能不同。

Running g++ -v -v -v outputs lots of things, including all the include directories searched.运行g++ -v -v -v会输出很多东西,包括搜索到的所有包含目录。 vector is in one of those. vector是其中之一。

On my Debian Stable system vector is here:在我的 Debian Stable 系统上, vector在这里:

/usr/include/c++/4.4/vector

On a "plain" ubuntu install you have to install在“普通”ubuntu 安装中,您必须安装

libstdc++- version -dev libstdc++-版本-dev

to get the header files.获取头文件。

then cheking the installed files you'll get the path !然后检查已安装的文件,您将获得路径!

In many IDE (eg NetBeans) you may use Ctrl+Click to className to go to definition在许多 IDE(例如 NetBeans)中,您可以使用Ctrl+Click to className 来定义

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.您可以使用 bash 工具“定位”来搜索您知道在库中的任何文件。 eg.例如。 "locate stl_multimap.h" for me yields: “定位 stl_multimap.h” 对我来说产生:

/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.对于我的计算机,所有 gcc 7.* 文件都在我的/usr/include/c++/7目录中。

If for some horrible reason you use Windows, I'm sure that you'll be able to find an equivalent command with Powershell.如果出于某种可怕的原因您使用 Windows,我相信您将能够找到与 Powershell 等效的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM