【问题标题】:From one cpp give list of the head file and hpp file used从一个 cpp 给出使用的头文件和 hpp 文件的列表
【发布时间】:2018-05-20 15:40:54
【问题描述】:

我想列出与这个.cpp 文件相关的所有头文件和.hpp 文件。 该列表还需要包含子头文件、.h 文件和.hpp 文件。我该怎么做?

【问题讨论】:

  • 检查您的编译器文档。许多编译器都有命令行选项来输出头文件依赖项。
  • 如果您使用 G++(来自 GCC — GNU Compiler Collection 的 C++),那么 -H 选项会写入(在 stderr 上)您寻找的信息。

标签: c++ header-files code-organization


【解决方案1】:

我不确定您所说的“头文件”是什么意思。

但您可能会发现以下内容很有用。 (我的 makefile 中有。)

.PHONY: 依赖 .depends: *.hh $(CC) $(CC_FLAGS) -M *.cc > .depends

它在我命名为“.depends”的文件中生成大量信息。

HelloWorld.cc 是 10 行。

依赖贡献的典型输出:

HelloWorld.o: HelloWorld.cc /usr/include/stdc-predef.h \
 /usr/include/c++/7/iostream \

...

 /usr/include/c++/7/bits/basic_ios.tcc \
 /usr/include/c++/7/bits/ostream.tcc /usr/include/c++/7/istream \
 /usr/include/c++/7/bits/istream.tcc

总行数约 1870 行。

使用g++ v7.2.0,ubuntu 17.10 (64)

【讨论】:

  • “.depends”文件有“.h”文件,“.hh”文件(我的代码)和“.hpp”文件,也许还有一些你认为你不想要的文件(所以过滤他们出去)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-08
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多