Linux 中 C++ 的类层次结构/依赖关系图生成器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8509243/
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
Class hierarchy/dependency diagram generator for C++ in Linux
提问by smilingbuddha
Is there some tool to generate class hierarchy/dependency diagrams by inspecting C++ code in Linux?
是否有一些工具可以通过检查 Linux 中的 C++ 代码来生成类层次结构/依赖关系图?
I have this big collection of C++ files given to me and such a tool would be invaluable to help me understand the source code. I am getting a little tangled up in understanding it.
我有一大堆 C++ 文件给我,这样的工具对于帮助我理解源代码非常有用。我对它的理解有点纠结。
采纳答案by fefe
Try doxygen. It may also be shipped with your distribution.
试试doxygen。它也可能随您的发行版一起提供。
You may need GraphVizto generate the graphs. There is a simple exampleand output.
您可能需要GraphViz来生成图形。有一个简单的例子和输出。
And this is a more complicated example from the legend file generated by doxygen:
这是来自 doxygen 生成的图例文件的一个更复杂的示例:
Code (NOTE: if you only want to generate the graphs, the comments are not required.):
代码(注意:如果您只想生成图形,则不需要注释。):
/*! Invisible class because of truncation */
class Invisible { };
/*! Truncated class, inheritance relation is hidden */
class Truncated : public Invisible { };
/* Class not documented with doxygen comments */
class Undocumented { };
/*! Class that is inherited using public inheritance */
class PublicBase : public Truncated { };
/*! A template class */
template<class T> class Templ { };
/*! Class that is inherited using protected inheritance */
class ProtectedBase { };
/*! Class that is inherited using private inheritance */
class PrivateBase { };
/*! Class that is used by the Inherited class */
class Used { };
/*! Super class that inherits a number of other classes */
class Inherited : public PublicBase,
protected ProtectedBase,
private PrivateBase,
public Undocumented,
public Templ<int>
{
private:
Used *m_usedClass;
};
Result:
结果:
You do notneed to comment your code to generate these graphs. The first example has no comments at all. The second example has one class without doxygen style comment. Just set the appropriate parameter (at least EXTRACT_ALL = YES
should be set. I cannot recall whether this is all that is needed).
你并不需要注释你的代码来生成这些图表。第一个示例根本没有注释。第二个示例有一个没有 doxygen 样式注释的类。只需设置适当的参数(至少EXTRACT_ALL = YES
应该设置。我不记得这是否是所有需要的)。
回答by Kamyar Souri
If you use Eclipse as IDE, you can use type hierarchy to see class hierarchy.
如果您使用 Eclipse 作为 IDE,则可以使用类型层次结构来查看类层次结构。
回答by B?ови?
If you use kdevelop, you could install kdevcontrolflowgraphview plugin.
如果你使用 kdevelop,你可以安装kdevcontrolflowgraphview 插件。
回答by thegreendroid
There's a promising new tool called cpp-depenencies
.
有一个很有前途的新工具叫做cpp-depenencies
.
It can generate component
dependency diagrams (like below) as well as class
hierarchy diagrams (by passing an option to treat each source file as a component).
它可以生成component
依赖关系图(如下所示)以及class
层次结构图(通过传递一个选项来将每个源文件视为一个组件)。
There's also cpp_dependency_graph
, which is able to generate component/include dependency graphs in dot
, d3.js
or JSON formats.
还有cpp_dependency_graph
,它能够生成组件/包括依赖关系图dot
,d3.js
或JSON格式。
Below is an example d3.js
visualisation.
下面是一个示例d3.js
可视化。
Disclaimer - I am the author of cpp_dependency_graph
.
免责声明 - 我是cpp_dependency_graph
.