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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11457670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 13:47:36  来源:igfitidea点击:

Where are the headers of the C++ standard library

c++linuxstlheader-filesc++-standard-library

提问by Thomas

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)

我想知道在我的文件系统上哪里可以找到 C++ 标准库的头文件。特别是我正在寻找矢量模板的定义。我在 /usr/include/ 和各种子目录中搜索。我还尝试了 'locate vector.h',它带来了许多向量的实现,但不是标准的实现。我错过了什么?(发行版为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 内部发生的事情,但我不确定。

采纳答案by Mike Seymour

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

GCC 通常将标准 C++ 头文件安装在/usr/include/c++/<version>/. 您可以运行gcc -v以找出您安装了哪个版本。

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.

至少在我的版本中,没有vector.h; 公共标头只是vector(没有扩展名),大部分实现都在bits/stl_vector.h.

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

我的 Ubuntu 发行版就是这种情况;您的分布可能会有所不同。

回答by RiaD

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

在许多 IDE(例如 NetBeans)中,您可能会使用Ctrl+ClickclassName 来定义

回答by genpfault

On my Debian Stable system vectoris here:

在我的 Debian 稳定版系统vector上:

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

回答by R. Martinho Fernandes

Running g++ -v -v -voutputs lots of things, including all the include directories searched. vectoris in one of those.

运行会g++ -v -v -v输出很多东西,包括搜索到的所有包含目录。vector是其中之一。

回答by jo_

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 !

然后检查已安装的文件,您将获得路径!

回答by Elliott

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:

您可以使用 bash 工具“定位”来搜索您知道在库中的任何文件。例如。“定位 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++/7directory.

在每个位置,我都会找到文件的不同编译器版本。对于我的计算机,所有 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 找到等效的命令。