查看包含依赖项

时间:2009-01-09 02:27:21

标签: c++ code-analysis analysis

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

2 个答案:

答案 0 :(得分:3)

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 '

或者那对你来说太过分了吗?

(在Windows下,总是有cygwin。)

答案 1 :(得分:1)

试试这个

Tool to track #include dependencies

写一个自己的作品听起来也很简单。添加“冗余”包括确定虽然可能更具挑战性。人们必须解析并遵循ifdef之类的东西。但是,仅仅创建一个依赖树,它是非常简单的。

相关问题