【问题标题】:Viewing include dependencies查看包含依赖项
【发布时间】:2009-01-09 02:27:20
【问题描述】:

有没有人知道一种工具可以分析 C++ 代码库并显示哪些文件包含哪些头文件并突出显示冗余包含的图形表示?我使用了理解 C++,但它很昂贵,并且在大型(且封装不佳)代码库上很快变得非常笨拙。

【问题讨论】:

  • Tim 强调的问题重复

标签: c++ code-analysis analysis


【解决方案1】:

gcc/g++ 总是有 "-H" 选项...

例如:% g++ -H foo.C

'-H'
     Print the name of each header file used, in addition to other
     normal activities.  Each name is indented to show how deep in the
     '#include' stack it is.  Precompiled header files are also
     printed, even if they are found to be invalid; an invalid
     precompiled header file is printed with '...x' and a valid one
     with '...!' .

然后:

  • 'sed' 或 'awk' 删除前导 '...'。
  • '排序使相同的名称相邻。
  • 'uniq -c' 来计算名字。
  • 'grep -v' 删除单例。

如:

%  g++ -H  foo.C |& awk '{print $2}' | sort | uniq -c | grep -v '      1 '

或者这对你来说太 linux'y / unix'y?

(windows下,总有cygwin。)

【讨论】:

    【解决方案2】:

    试试这个

    Tool to track #include dependencies

    自己编写一个听起来也是一个非常简单的练习。添加“冗余”包括决心虽然可能更具挑战性。必须解析并遵循 ifdefs 等。但是对于仅仅创建一个依赖树来说它是非常简单的。

    【讨论】:

      猜你喜欢
      • 2015-10-09
      • 2014-04-04
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多